How to get my Action method to give me back my model from web grid with checkboxes
I have a strongly typed view which is uses an IEnumerable as its model.
There's a bool property on the model which I'm rendering in a MVC WebGrid in a checkbox which the user can then check or uncheck.
On submit it gets to my action method but how do I get the checked checkboxes?
If I look at the Request.Params, I see all the checked checkboxes coming back as parameters. Is there any easy way for the DefaultModelBinder to convert these back into my IEnumerable, or do I have to do this by hand?
Here's my View so far:
@model IEnumerable<XXX.XXXItemDto>
<div id="items">
@using (Ajax.BeginForm("SaveEvents", "MyController", new AjaxOptions { UpdateTargetId = "items" }))
{
var grid = new WebGrid(Model, canPage: false, canSort: false);
@grid.GetHtml(columns: grid.Columns(
grid.Column("itemDescription", header: "Event"),
grid.Column("acknowledged", format: @<text><input name="Acknowledged_@(item.staffItemOid)" type="checkbox" value="@item.staffItemOid"开发者_JAVA百科 @(item.acknowledged ? "Checked" : null)/> </text>, header: "Acknowledged")
))
@Html.SubmitButton("Save")
}
</div>
精彩评论