开发者

Escape html with mvc3 razor

I'm trying to create a link tha开发者_运维技巧t just triggers a javascript function with parameters set by my mvc model. I have something that looks like this

<a onclick="$('foo_@Model.bar').toggle()"></a>

However this literally makes the onclick element 'foo@Model.bar' instead of printing the contents of Model.bar. How do I escape the Html without altering it?


Just add brackets, tested it and works fine:

<a onclick="$('foo_@(Model.bar)').toggle()"></a>


Just add parenthesis:

<a onclick="$('foo_@(Model.bar)').toggle()"></a>


<a onclick="$(@string.Format('foo_{0}',Model.bar)).toggle()"></a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜