我想使用自定义帮助器方法显示部分视图。唯一的问题是,我无法克服这个语法问题。为这个cshtml文件设置的模型是我定义为Operation的一个IEnumerable模型集合。我相信这是一个简单的解决方法。下面是我所看到的例子:语法问题 - Razor MVC4
我的代码块:
@using(Html.BeginForm()) {
<div id="editor_rows">
@foreach (var item in Model){
Html.RenderPartial("OperationEditorRow", item);
}
</div>
}
这给了我以下运行时错误:
Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code.
但如果我删除了@在foreach语句前面签名,一切都被解释为纯文本。于是,我就放置一个@的HTML面前如下:
@using(Html.BeginForm()) {
<div id="editor_rows">
@foreach (var item in Model){
@Html.RenderPartial("OperationEditorRow", item);
}
</div>
}
这回来了,说编译错误:
Cannot implicitly convert type void to object
如果我要离开这儿的项目,我得到一个运行时错误说:
The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
我假设这是有关的前一个错误。如果有人对我有什么建议,请帮忙。
尝试使用'Partial'而不是'RenderPartial' – lucask
您的代码看起来不错。尝试重新启动Visual Studio。已经知道要解决这样的一些异常现象。 –
感谢您的建议。我尝试了他们,但我仍然看到相同的错误。我认为问题的核心在于第二个错误消息:无法将类型void无意中转换为对象 –