开发者

Escape html with mvc3 razor

开发者 https://www.devze.com 2023-03-13 06:15 出处:网络
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

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

精彩评论

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