2012-07-09 52 views
0

破碎的RenderPartial我已經走到了MVC3項目,我之前已經停止工作一個星期撰寫並拋出以下錯誤:與MVC3

Error 10 The call is ambiguous between the following methods or properties: 'System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(System.Web.Mvc.HtmlHelper, string)' and 'System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(System.Web.Mvc.HtmlHelper, string)'

,這是什麼原因呢?最近項目中我沒有改變任何東西,因爲它是博克。我把它看起來像這樣的代碼:

<div class="page-body"> 
    @if(!String.IsNullOrWhiteSpace(ViewBag.ErrorMessage)) { 
     // Output error message 
     Html.Raw(ViewBag.ErrorMessage); 
    } else { 
     // Render upload form 
     Html.RenderPartial("_UploadForm"); 
    } 
</div> 

回答

1

你缺少@符號前面的Html.Raw的,因爲德法reutrns一個字符串返回,因此需要@symbol

For your knowledge taken from MSDN : The Razor syntax @ operator HTML-encodes text before rendering it to the HTTP response. This causes the text to be displayed as regular text in the web page instead of being interpreted as HTML markup.

請使用這樣

<div class="page-body"> 
    @if(!String.IsNullOrWhiteSpace(ViewBag.ErrorMessage)) { 
     @Html.Raw(ViewBag.ErrorMessage); 
    } else { 
     // Render upload form 
     Html.RenderPartial("_UploadForm"); 
    } 
</div> 
+0

爾加盯着它相當長的一段時間,由於經過這麼簡單! – Lloyd 2012-07-09 13:21:04