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?
<%=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) Html.Raw()
(so that it doesn't get HTML encoded before rendering) @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")
)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.