0
public ActionResult Default()
{
    ViewBag.Message = "Hello,World!";
    var template = "<h1>@ViewBag.Message</h1>";
    //How to make the content of the following "View" = "template"
    return View();
}

然后构建html结果为:

<h1>Hello,World!</h1>

请帮助我,谢谢!我知道 RazorEngine 可以解析 Razor 文件,但不能将字符串渲染到 View。

4

1 回答 1

0

改用内容结果,它返回原始内容。它不使用关联视图,而只是将内容直接返回给请求者。

return Content(template);
于 2013-02-08T21:04:18.150 回答