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>
精彩评论