开发者

MVC3 - Error rendering partial view

开发者 https://www.devze.com 2023-03-13 02:22 出处:网络
why do开发者_StackOverflow中文版es this error occur.. The best overloaded method match for \'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)\' has some invalid argumen

why do开发者_StackOverflow中文版es this error occur.. The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments...when I am trying to put a partial view in a div like

  <div>@Html.RenderPartial("_pagePartial");</div>

thanks for your help.


Because the correct syntax is this (notice the { }s):

<div>@{Html.RenderPartial("_pagePartial");}</div>

or if you prefer:

<div>@Html.Partial("_pagePartial")</div>

The reason for this is that contrary to the Partial extension method RenderPartial doesn't return anything. It directly writes to the output stream. Contrast this with the WebForm equivalents:

<% Html.RenderPartial("_pagePartial"); %>
<%= Html.Partial("_pagePartial") %>
0

精彩评论

暂无评论...
验证码 换一张
取 消