Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you should be able to generate a view based on dynamically generated model, For that you shouldn't give chance to make changes to name part of keyvalue pair right, so remove textbox for that like,</p> <pre><code>using(Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "parameterForm" })) { &lt;div id="inputBoxesDIV"&gt; for(int i = 0; i &lt; Model.GetParameters().Count; i++) { &lt;label&gt;Model.GetParameters().ElementAt(i).Name&lt;/label&gt; Html.TextBoxFor(m =&gt; m.GetParameters().ElementAt(i).Value, new { name =Model.GetParameters().ElementAt(i).Name , size = 60 }) } &lt;/div&gt; } </code></pre> <p>so user will make changes to value textboxes, so after he submits your able to read all values using key names,</p> <pre><code>[HttpPost] public ActionResult Index(FormCollection formCollection) { foreach (var key in formCollection.AllKeys) { var value = formCollection[key]; } foreach (var key in formCollection.Keys) { var value = formCollection[key.ToString()]; } } </code></pre> <p>If you want to give the users the ability to modify both name and value in key value pair, Then you should try like this,</p> <pre><code> using(Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "parameterForm" })) { &lt;div id="inputBoxesDIV"&gt; for(int i = 0; i &lt; Model.GetParameters().Count; i++) { &lt;input type="text" name="@String.Format("name{0}",i)" value="@Model.GetParameters().ElementAt(i).Name" size="20"/&gt; &lt;input type="text" name="@String.Format("value{0}",i)" value="@Model.GetParameters().ElementAt(i).Value" size="60"/&gt; } &lt;/div&gt; } </code></pre> <p>and in your post action,</p> <pre><code>[HttpPost] public ActionResult Index(FormCollection formCollection) { for(int i=0;i&lt;formCollection.AllKeys.Length;i++) { var value = formCollection["value"+i]; var name=formCollection["name"+i]; } } </code></pre> <p>Hope this helps.</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.
    1. This table or related slice is empty.
    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