在MVC中使用HTML帮助器动态添加onclick [英] Adding a onclick dynamically using an Html Helper in MVC

查看:83
本文介绍了在MVC中使用HTML帮助器动态添加onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用HTML Helper动态设置onclick的功能.以下是我要执行的操作,但出现明显的语法错误

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) %>');"})%>

推荐答案

第一步是从<%= Html.Encode(item.ID)%>中删除<%=%>,然后调用Html .Encode(item.ID)直接.对item.NUMBER编码进行同样的操作.

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.

类似的东西:

"ajaxThis(this, " + Html.Encode(item.ID) + ", '" + Html.Encode(item.NUMBER) + "');"

这篇关于在MVC中使用HTML帮助器动态添加onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆