html.checkbox - explicit value to hidden field value
Posted
by Tassadaque
on Stack Overflow
See other posts from Stack Overflow
or by Tassadaque
Published on 2010-06-16T10:00:55Z
Indexed on
2010/06/16
20:02 UTC
Read the original article
Hit count: 374
asp.net-mvc
|html-helper
Hi I am creating list of checkboxes in partial view by follwoing http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/
code and Rendered HTML for checkboxes is as follows
<%=Html.CheckBox("EmployeeID", new { value = user.EmployeeID, @class = "ccboxes", title = user.Designation + "(" + user.EmployeeName + ")" })%>
<INPUT id=MemoUsers_a29f82e4-ebbc-47b0-8cdd-7d54f94143be__EmployeeID class=boxes title=Programmer(Zia) value=6 type=checkbox name=MemoUsers[a29f82e4-ebbc-47b0-8cdd-7d54f94143be].EmployeeID jQuery1276681299292="27">
<INPUT value=false type=hidden name=MemoUsers[a29f82e4-ebbc-47b0-8cdd-7d54f94143be].EmployeeID>
In rendered html it can be seen that value attribute of hidden field is false. i want to assign explicit value(same as checkbox value) to this value. Is this possible using html.checkbox or html.checkboxfor.
one way is recommended in http://stackoverflow.com/questions/626901/asp-net-mvc-rc2-checkboxes-with-explicit-values. Is there any other better way
i want to do this as ModelState.IsValid is returning false because of hidden field value attribute
Regards
© Stack Overflow or respective owner