1.新建控制器HtmlStr
public ActionResult HtmlStr()
{
ViewData["strScript"] = "<script>alert('Hello');</script>";//弹出一个对话框
ViewData["inputA"] = new HtmlString("<a href='javascript:void(0)'>编辑1</a>");//创建a标签
ViewData["inputB"] = new MvcHtmlString("<a href='javascript:void(0)'>编辑2</a>");//创建a标签
return View();
}
2.新建视图HtmlStr
@Html.Raw(ViewData["strScript"])
@ViewData["inputA"]
@ViewData["inputB"]