2013-04-08 21 views
1

添加自定義的控件將引發以下錯誤: -添加自定義控制罰全中查看錯誤

"\\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")的位置使頁面完美呈現。

+1

那麼......錯誤是什麼?部分位於哪裏? – 2013-04-08 05:41:16

+0

@SimonWhitehead,部分位於共享文件夾 – 2013-04-08 06:07:45

+0

@SimonWhitehead,它會拋出以下錯誤: - 「\\ Views \\ Error \\ Index.cshtml(9):錯誤CS1502:'System.Web最好的重載方法匹配。 WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)'有一些無效的參數「 – 2013-04-08 06:15:33

回答

1

由於您使用RenderPartial的方式,您正在收到該錯誤。您應該做的:

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

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

See this SO question額外的學習。

+0

歡迎您,很高興它的工作 – 2013-04-08 06:36:39