I have a simple code that contain ViewBag boolean value which success bind with true or false value to input type cshtml.
But I have a problem when post to Controller which value from ViewBag is always false when post from cshtml, wheater i change true or false.
[HttpPost]
[Route("~/summary")]
public IActionResult Index(WorkOrder data)
{
ViewBag.IsMaintenence = model.IsMaintenence;
Return View(model)
}
@{
Layout = null;
ViewBag.Title = "WorkOrder";
var _ismaintenence = (bool)(ViewBag.IsMaintenence == null ? false : ViewBag.IsMaintenence);
}
@using (Html.BeginForm("Index", "WO", FormMethod.Post))
{
<input type="checkbox" id="IsMaintenence" name="IsMaintenence" value="true" checked="@_ismaintenence">
<button type="submit" class="btn btn-info">Update</button>
}
Thank you