Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Html.BeginForm with querystring
    primarykey
    data
    text
    <p>My url looks like this: </p> <pre><code>customer/login?ReturnUrl=home </code></pre> <p>In the login view, I have used this pattern of code which works fine.</p> <pre><code>@using(Html.BeginForm()) { ... } </code></pre> <p>This magically generates following html</p> <pre><code>&lt;form action="customer/login?ReturnUrl=home" method="post"&gt; </code></pre> <p>But now, I need to add an attribute (e.g., <code>data-id="something"</code>) in the form. How can I do that? If I don't have any query string, I know I can do something like this:</p> <pre><code>@using(Html.BeginForm(action, controller, FormMethod.Post, new { data_id="something" })) </code></pre> <p>But don't know how to add querystring which should be in html:</p> <pre><code>&lt;form action="customer/login?ReturnUrl=home" method="post" data-id="something"&gt; </code></pre> <p>I thought about using <code>&lt;form&gt;</code> directly but don't know how to specify querystring which is variable. And I have no idea how to achieve it with <code>Html.BeginForm</code>. Any tip would be appreciated. </p> <p><strong>RESOLUTION:</strong></p> <p>For now, I used <code>&lt;form&gt;</code> with following hint <a href="https://stackoverflow.com/questions/7323707/how-to-get-current-url-value-in-view">How to get current url value in View</a>. The resulting view looks like</p> <pre><code>&lt;form action="@Request.Url.PathAndQuery" data-id="something" method="POST"&gt; </code></pre> <p>But it would be nice to have an overloaded method of <code>BeginForm</code> for this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload