Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Matthew said, if you don't want to change the URL and don't want to use javascript, your best option is a POST request to the server. In ASP.Net MVC this can be pretty neatly done, however. You'll need to modify the <strong><code>View</code></strong> with two additions, and add a new <strong><code>ActionMethod</code></strong>.</p> <p><strong>The View, part 1</strong><br> Add an extra form to your view (this is not allowed in WebForms, so it might feel a little strange, but it is perfectly fine in MVC).</p> <pre><code>&lt;form action="/myController/myView/&lt;%= (ViewData["fieldCount"]+ 1) %&gt;"&gt; &lt;input type="submit" value="Add custom field" /&gt; &lt;/form&gt; </code></pre> <p>Note the <code>fieldCount</code> variable - this should be passed down from the <code>Controller</code> as presented below:</p> <p><strong>The Controller</strong><br> Add the following <code>ActionMethod</code> to overload the one you currently have to display your form:</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public ActionResult myView(int id) { ViewData["fieldCount"] = id; Return View(); } </code></pre> <p>I used the variable name <code>id</code> just so you wouldn't have to add another route.</p> <p><strong>The View, part 2</strong><br> Now, as you have a known fieldcount, so you can just loop out the fields on the view:</p> <pre><code>&lt;form action="/myController/SaveData/" method="post"&gt; ... &lt;% for(i=0; i&lt;int.TryParse(ViewData["fieldCount"]); i++) { %&gt; &lt;input type="text" name="customData" /&gt;&lt;br /&gt; &lt;% } %&gt; ... &lt;/form&gt; </code></pre> <p>Note that the two forms have different actions - that way, you will never have to worry that clicking one submit button will accidentally post the wrong data.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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