Syntax release - Razor MVC4

I am trying to display a partial view using a special helper method. The only problem: I can not get through this syntax problem. The model installed for this cshtml file is a collection of IEnumerable models, which I defined as "Operation". I am sure this is easy to fix. Here is an example of what I see:

I have this code block:

@using(Html.BeginForm()) { <div id="editor_rows"> @foreach (var item in Model){ Html.RenderPartial("OperationEditorRow", item); } </div> } 

This gives me the following runtime error:

  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 before the foreach statement, everything is interpreted as plain text. So I tried to put @ before Html like this:

  @using(Html.BeginForm()) { <div id="editor_rows"> @foreach (var item in Model){ @Html.RenderPartial("OperationEditorRow", item); } </div> } 

This returns with a compilation error that states:

  Cannot implicitly convert type void to object 

If I run the project here, I get a runtime error that reads:

  The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments 

I assume this is due to a previous error. If anyone has a suggestion for me, please help.

+6
source share
2 answers

The problem is resolved. I worked on this with a colleague. It turns out that the error related to the recording method indicated a problem inside my partial view. I used @ {} around the code block inside, which most likely also caused other syntax errors. Thanks for answers.

+1
source

Add {} around your render call, for example @ {RenderPartial ...}

0
source

Source: https://habr.com/ru/post/918990/


All Articles