Adding dynamic onclick with Html Helper in MVC
I need the ability to dynamically set onclick using an HTML helper. below is what I am trying to do, but I am getting an obvious syntax error.
<%=Html.CheckBox("checkboxname", item.Id = 3, New With {.onclick = "ajaxThis(this, <%= Html.Encode(item.ID) %>, '<%= Html.Encode(item.NUMBER) %>');"})%>
0
a source to share
2 answers
You are entering a string, so just run the following line:
<%= Html.CheckBox("checkboxname", item.Id = 3, New With {.onclick = String.Concat("ajaxThis(this, ", Html.Encode(item.ID), ", '", Html.Encode(item.NUMBER), "');")})%>
However, it would be easier to just add a css class and hook up an event handler using jQuery .
+1
a source to share