[英]How do I rewrite this into MVC Razor 3?
Its a simple snippet, but the .replace is not being recognize in my mvc razor view: I replaced <%= %> with @ , not sure what else is needed? 它是一个简单的代码段,但是在我的mvc剃刀视图中无法识别.replace:我用@替换了<%=%> ,不确定还需要什么吗?
<%=Ajax.ActionLink("[replacethis]",
"ToggleEnabled",
new { id = Model.ID },
new AjaxOptions { UpdateTargetId = "toggleimage" + Model.ID }).Replace("[replacethis]",
string.Format("<div id='toggleimage{0}'><img src='/Content/icons/{1}' border='0' alt='toggle'/></div>",
Model.ID, Model.Enabled ? "tick.png" : "tick_grey.png"))%>
I'm not sure if this is the ideal, but you can get what you're after by: 我不确定这是否理想,但您可以通过以下方式获得所需的服务:
.ToHtmlString()
(ie, convert MvcHtmlString to a raw HTML string so that you can call Replace
on it) 插入.ToHtmlString()
(即,将MvcHtmlString转换为原始HTML字符串,以便可以在其上调用Replace
) Html.Raw()
(so that it doesn't get HTML encoded before rendering) 将整个内容包装在Html.Raw()
(这样一来,渲染之前就不会对HTML进行编码) @Html.Raw(
Ajax.ActionLink("[replacethis]",
"ToggleEnabled",
new { id = Model.ID },
new AjaxOptions { UpdateTargetId = "toggleimage" + Model.ID })
.ToHtmlString()
.Replace("[replacethis]",
string.Format("<div id='toggleimage{0}'><img src='/Content/icons/{1}' border='0' alt='toggle'/></div>",
Model.ID, Model.Enabled ? "tick.png" : "tick_grey.png")
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.