I'm still quite new to MVC and I'm wondering if I am implementing the following in a correct way.
I have a table that is being build in a foreach loop. On each row there is a dropdown box. I attached an eventlistener to the dropdown for on change using jQuery. In the onchange event I post my data. Now my biggest concern is how to retrieve the data for the row that was changed. I'm currently using a hiddenfield for this. In webforms, this would have been a simple repeater and than all the data would be available on postback. Please find a basic version of my loop below.
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Bar)
</td>
<td>
@Html.DropDownListFor(modelItem => item.Foo, new SelectList(item.Foos, "Id", "Name", item.FooID), htmlAttributes: new { @class = "form-control ddlFoo" })
@Html.HiddenFor(modelItem => item.Bar, htmlAttributes: new { @class = "hfBar" })
</td>
</tr>
}
So is this the correct approach? Or what would be a better way? Thank you for helping out a MVC newbie
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire