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>

Plaseは私を助けてくれてありがとう!RazorEngineはRazorファイルを解析できますが、文字列を表示にレンダリングできません。

4

1 に答える 1

0

代わりにコンテンツ結果を使用してください。これにより、生のコンテンツが返されます。関連するビューは使用せず、コンテンツをリクエスターに直接返すだけです。

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