0

I need the ability to dynamically set an onclick using an HTML Helper. the below is what I'm trying to do, but i'm 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

2 Answers 2

1

The first step would be to remove the <%= %> from <%= Html.Encode(item.ID) %> and just call Html.Encode(item.ID) directly. Do the same with the item.NUMBER encoding.

Something like:

"ajaxThis(this, " + Html.Encode(item.ID) + ", '" + Html.Encode(item.NUMBER) + "');"
Sign up to request clarification or add additional context in comments.

Comments

1

You're entering a string, so just concat the string instead:

<%= Html.CheckBox("checkboxname", item.Id = 3, New With {.onclick = String.Concat("ajaxThis(this, ", Html.Encode(item.ID), ", '", Html.Encode(item.NUMBER), "');")})%>

However, it would probably be easier to just add a css class and hook up an event handler using jQuery.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.