I have a grid which is by 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'd like to add a checkbox which would Post back to a controller. Something similar to this:
@using (Html.BeginForm("PostExample", "Home"))
{
<input type="hidden" name="SomeId" [email protected]/>
<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 of doing this? Any help would be greatly appreciated.
Your question is very unclear. Where do you want to show this checkbox? On each row? Dependent on some value of your model? If yes, then you could use a custom column, like this:
.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>
);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With