Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Razor 如何在WebApi应用程序中包含@RenderPage?_Razor_Asp.net Web Api - Fatal编程技术网

Razor 如何在WebApi应用程序中包含@RenderPage?

Razor 如何在WebApi应用程序中包含@RenderPage?,razor,asp.net-web-api,Razor,Asp.net Web Api,我正在开发一个Web Api应用程序,下面是代码中使用的razor模板 _layout.cshtml页面包含需要跨其他模板共享的页脚。下面是要跨模板共享的页脚 <p> This is footer </p> 这是页脚 我曾尝试使用以下内容共享页脚,但它无法呈现页面 @model SR.Services.External.Data.EmailNotificationModel <html> <head> <title>&l

我正在开发一个Web Api应用程序,下面是代码中使用的razor模板

_layout.cshtml页面包含需要跨其他模板共享的页脚。下面是要跨模板共享的页脚

<p> This is footer </p>
这是页脚

我曾尝试使用以下内容共享页脚,但它无法呈现页面

 @model SR.Services.External.Data.EmailNotificationModel
<html>
<head>
    <title></title>
</head>
<body style=\"color:#808080;font-size:8pt;font-family:Arial\">
    <p>
        Hi @Model.TargetUserName,
    </p>
    <p>
        You have been removed from community '@Model.ObjectName' by @Model.Initiator.
    </p>

    @Html.Partial("_layout.cshtml")
    @Html.Partial("~/EmailTemplates/_layout.cshtml")
    @RenderPage("~/EmailTemplates/_layout.cshtml")
    @RenderPage("_layout.cshtml")
  </body>
</html>
@model SR.Services.External.Data.EmailNotificationModel

嗨@Model.TargetUserName,

@Model.Initiator已将您从社区“@Model.ObjectName”中删除。

@Html.Partial(“_layout.cshtml”) @Html.Partial(“~/EmailTemplates/\u layout.cshtml”) @RenderPage(“~/EmailTemplates/\u layout.cshtml”) @渲染页面(“_layout.cshtml”)

非常感谢您的帮助。

不要使用
@RenderPage(“\u layout.cshtml”)
像这样做,
@Html.Partial(\u layout”)
。但我建议为页脚创建一个局部视图。例如_Footer.cshtml,只需呈现它而不是_布局_Layout.cshtml被用作母版页。其他方面,你可以像这样呈现布局页面
@RenderPage(“~/Views/Shared/\u Layout.cshtml”)
,这基本上就是我相信的页脚。我试过@RenderPage(“\u Layout.cshtml”)和@Html.Partial(\u Layout”)bt nothings似乎不起作用。我还创建了另一个共享文件夹,在其中放置了模板。但我无法同时呈现它。web api应用程序是否支持呈现页面?首先,您的问题是错误的。WebAPI和Asp.NETMVC都是独立的东西。您可以在Web Api中创建服务。无法在Web Api中返回/呈现视图。因此,如果您在单个项目中同时使用WebAPI和MVC,那么您的问题是MVC。我以上的评论是针对ASP.NETMVC的。并且您不能在Web Api中呈现/返回视图或页面。