问题描述
这工作,因为它返回局部视图渲染字符串中的结果:
This works, because it returns the result of partial view rendering in a string:
@Html.Partial("Path/to/my/partial/view")
但我preFER使用的RenderPartial
,似乎我需要写:
@{Html.RenderPartial("Path/to/my/partial/view");}
而不是:
@Html.RenderPartial("Path/to/my/partial/view");
要得到它的工作。错误信息:
To get it to work. Error message:
Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
如果有什么更好的办法,而不是开放code座 @ {...}
只是一个方法调用?
If there any better way instead of opening code block @{...}
just for one method call?
推荐答案
-
的RenderPartial()
是无效的方法的写入响应流。一个空洞的方法是,在C#中,需要;
,因此必须由括{}
RenderPartial()
is a void method that writes to the response stream. A void method is, in C#, needs a;
and hence must be enclosed by{ }
.部分()
是返回MvcHtmlString.在剃须刀,你可以调用属性或与返回这样的字符串的方法只是一个@
preFIX从你的页面上普通的HTML区分开来。Partial()
is a method that returns an MvcHtmlString. In Razor, You can call a property or a method that returns such a string with just a@
prefix to distinguish it from plain HTML you have on the page.这篇关于用剃刀Html.RenderPartial()语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!