Razor 如何在C中从MVC3中的字符串返回视图# public ActionResult Default() { Message=“你好,世界!”; var template=“@ViewBag.Message”; //如何制作以下“视图”=“模板”的内容 返回视图(); }

Razor 如何在C中从MVC3中的字符串返回视图# public ActionResult Default() { Message=“你好,世界!”; var template=“@ViewBag.Message”; //如何制作以下“视图”=“模板”的内容 返回视图(); },razor,view,Razor,View,然后将html结果构建为: 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结果构建为:

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();
}
你好,世界!

请帮帮我,谢谢!我知道RazorEngine可以解析Razor文件,但不能将字符串呈现给视图

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

<h1>Hello,World!</h1>

为什么?为什么不简单地使用正确的视图?这解决了什么问题?您的结果是:@ViewBag.MessageYes,true。没有看到“@”。是否可以这样做:
返回内容(“+ViewBag.Message.ToString()+”)
return Content(template);