Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess form values in controller, i'm trying to post whole grid back to post method ASP.net MVC
    primarykey
    data
    text
    <p>I displayed a list of data in form of a grid [basic html table] and placed text boxes so that we can edit inside the grid and post the values so that I can save it. The list is not big , around 5-10 rows in it.</p> <p>How to access these form values back in controller? <code>FormCollection</code> doesn't seem to work and I cannot even access the values through <code>Request.Form[]</code>. I want it back in a form of a list so that I can loop through it and get the new values.</p> <p><strong>.cshtml</strong></p> <pre><code> &lt;form action="/Parameter/StudentWeights" method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt; Category &lt;/th&gt; &lt;th&gt; CategoryAlias &lt;/th&gt; &lt;th&gt; YearCode &lt;/th&gt; &lt;th&gt; ClassKto8 &lt;/th&gt; &lt;th&gt; Class9to12 &lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; @foreach(var item in Model.StudentWeights) { &lt;tr&gt; &lt;td&gt; @Html.HiddenFor(modelItem =&gt; item.CategoryId) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.Category) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.CategoryAlias) &lt;/td&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.YearCode) &lt;/td&gt; &lt;td&gt; @Html.EditorFor(modelItem =&gt; item.ClassKto8) &lt;/td&gt; &lt;td&gt; @Html.EditorFor(modelItem =&gt; item.Class9to12) &lt;/td&gt; &lt;/tr&gt; } &lt;/table&gt; &lt;input type="submit" value = "Submit" /&gt; &lt;/form&gt; </code></pre> <p><strong>controller</strong></p> <pre><code>[HttpPost] public ActionResult studentWeights(FormCollection collection) { try { // TODO: Add update logic here //service. foreach (var item in collection) { int x = item. // i want to loop through it and access the values. } } catch { return View(); } } </code></pre> <p>please help me how to get these values. I don't want to use JEditable or any third party jQuery tools.</p> <p>Is there any way to create a custom type and assign values in JavaScript or jQuery upon button click and then send it to my controller action?</p> <p>Thank you very much, any suggestion would be much helpful.</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.
 

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