在View中添加自定义控件会引发以下错误: -
"\\Views\\Error\\Index.cshtml(9): error CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments"
以下是索引页面的代码: -
@{
ViewBag.Title = "Error";
}
<h2>
Sorry, an error occurred while processing your request.
</h2>
<div>@Html.RenderPartial("MyUserControl")
以下是MyUserControl的代码: -
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
hi
从视图中删除@Html.RenderPartial("MyUserControl")
可以完美呈现页面。
答案 0 :(得分:1)
由于您使用RenderPartial的方式,您收到了该错误。你应该这样做:
<div>@Html.Partial("MyUserControl")</div>
或
<div>@{ Html.RenderPartial("MyUserControl"); }</div>
See this SO question了解更多信息。