I’m trying to display a partial view using a custom helper method. The only problem is, I can’t get past this syntax issue. The model set for this cshtml file is an IEnumerable collection of models I’ve defined as Operation. I’m sure this is an easy fix. Here’s an example of what I’m seeing:
I have this block of code:
@using(Html.BeginForm()) {
<div id="editor_rows">
@foreach (var item in Model){
Html.RenderPartial("OperationEditorRow", item);
}
</div>
}
This gives me the following error at runtime:
Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code.
But if I remove the @ sign in front of the foreach statement, everything is interpreted as plain text. So I tried placing an @ in front of Html as follows:
@using(Html.BeginForm()) {
<div id="editor_rows">
@foreach (var item in Model){
@Html.RenderPartial("OperationEditorRow", item);
}
</div>
}
This comes back with a compilation error that says:
Cannot implicitly convert type void to object
If I run the project from here, I get a runtime error that says:
The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
I’m assuming this is related to the previous error. If anybody has a suggestion for me, please help.
Problem solved. I worked on this with a coworker. It turns out the error refferring to the write method pointed to a problem inside my partial view. I was using @{} around a block of code inside of there, which was most likely throwing the other syntax errors also. Thanks for the responses.