Checkbox response in Html.Grid

I have a grid that is an IList:

@Html.Grid(Model.ExampleList).Columns(c =>
{
    c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateRequested)).Named("Date Requested");
    c.For(a => a.Comment).Named("Comment");
})

But I would like to add a flag that will send back to the controller. Something like this:

@using (Html.BeginForm("PostExample", "Home")) 
{
    <input type="hidden" name="SomeId" value=@ViewBag.SomeId/>
    <input type="hidden" name="AnotherId" value="AnotherId" />
    @Html.CheckBox("Complete", Model.Complete, new { onClick = "$(this).parent('form:first').submit();"
});

But I'm not sure how to combine them. What is the best way to do this? Any help would be greatly appreciated.

+3
source share
1 answer

Your question is very unclear. Where do you want to show this flag? In each line? Depending on some cost of your model? If so, then you can use your own column, for example:

.Columns(c =>
{
    c.Custom(
        @<text>
            <form action="@Url.Action("PostExample", "Home")" method="post">
                <input type="hidden" name="SomeId" value="@ViewBag.SomeId" />
                <input type="hidden" name="AnotherId" value="AnotherId" />
                @Html.CheckBoxFor(x => item.Complete, new { onclick = "$(this).parent('form:first').submit();" })
            </form>
        </text>
    );
})
+2
source

All Articles