简体   繁体   English

使用MVC3损坏的RenderPartial

[英]Broken RenderPartial with MVC3

I've come to an MVC3 project I wrote just a week ago which has stopped working and is throwing the following error: 我来到一个星期前写的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) ' 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) '

What is the reason for this? 这是什么原因呢? I haven't changed anything in project recently for it to bork. 我最近没有更改项目中的任何内容,因此无法正常工作。 The code I call it in looks like this: 我称之为的代码如下所示:

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

You are missing @ symbols front of your Html.Raw because teh method reutrns a string back hence requires the @symbol 您缺少Html.Raw的@符号,因为此方法返回字符串,因此需要@symbol

For your knowledge taken from MSDN : The Razor syntax @ operator HTML-encodes text before rendering it to the HTTP response. 据您了解,来自MSDN的知识: Razor语法@运算符在将文本呈现到HTTP响应之前对其进行HTML编码。 This causes the text to be displayed as regular text in the web page instead of being interpreted as HTML markup. 这将导致文本在网页中显示为常规文本,而不是被解释为HTML标记。

Please use it this way 请这样使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM