asp.net mvc 3 - Unexpected "foreach" keyword after "@" character -


i have partial view done in razor. when run following error - seems razor gets stuck thinking i'm writing code everywhere.

unexpected "foreach" keyword after "@" character. once inside code, not need prefix constructs "foreach" "@"

here view:

@model ienumerable<somemodel>  <div> @using(html.beginform("update", "usermanagement", formmethod.post)) {      @html.hidden("userid", viewbag.userid)  @foreach(var link in model) {     if(link.linked) {          <input type="checkbox" name="userlinks" value="@link.id" checked="checked" />@link.description<br />     } else {          <input type="checkbox" name="userlinks" value="@link.id" />@link.description<br />              } }  } </div> 

inside using block, razor expecting c# source, not html.

therefore, should write foreach without @.

inside html tag, razor expects markup, use @.

for example:

<div>     <!-- markup goes here -->     @if (x) {         //code goes here         if (y) {             //more code goes here             <div>                 <!-- markup goes here -->                 @if (z) { }             </div>         }     } </div> 

you need @ if want put code it's expecting markup, or if want write output anywhere.

to put non-tag-like markup it's expecting code, use @: or <text>.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -