Note that there are some explanatory texts on larger screens.

plurals
  1. POSyntax Issue- Razor MVC4
    text
    copied!<p>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:</p> <p>I have this block of code:</p> <pre><code> @using(Html.BeginForm()) { &lt;div id="editor_rows"&gt; @foreach (var item in Model){ Html.RenderPartial("OperationEditorRow", item); } &lt;/div&gt; } </code></pre> <p>This gives me the following error at runtime:</p> <pre><code> Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code. </code></pre> <p>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:</p> <pre><code> @using(Html.BeginForm()) { &lt;div id="editor_rows"&gt; @foreach (var item in Model){ @Html.RenderPartial("OperationEditorRow", item); } &lt;/div&gt; } </code></pre> <p>This comes back with a compilation error that says:</p> <pre><code> Cannot implicitly convert type void to object </code></pre> <p>If I run the project from here, I get a runtime error that says:</p> <pre><code> The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments </code></pre> <p>I'm assuming this is related to the previous error. If anybody has a suggestion for me, please help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload