Vanaraj n

Vanaraj n

  • NA
  • 18
  • 14.4k

MVC Unexpected "foreach" keyword after "@" character.

Aug 5 2016 10:15 PM
This is my code i am getting above said error :
@model IEnumerable<Bridgeratings.Models.SearchPage>
@{
ViewBag.Title = "SearchView";
WebGrid grid = new WebGrid();
}
<h2>SearchView</h2>
@using (Html.BeginForm("SearchView", "Search", FormMethod.Get))
{
@Html.AntiForgeryToken()
@foreach (var post in Model) {
<div>
<div class="form-group">
Html.LabelFor(model => post.clearance_route, new { class = "control-label col-md-2" })
<div class="col-md-10">
Html.EditorFor(model => post.clearance_route)
Html.ValidationMessageFor(model => post.clearance_route)
</div>
</div>
<input type="submit" value="Search" id="btnSubmit" />
</div>
}
}
<div id="DivGrid">
@{
var grid1 = new WebGrid(source: Model, canPage: true, rowsPerPage: 4, defaultSort: "line_segment");
@grid1.GetHtml(tableStyle: "PGrid", headerStyle: "Header", alternatingRowStyle: "altRow", htmlAttributes: new { id = "DataTable" }, columns: grid.Columns(
grid1.Column("clearance_route"),
grid1.Column("line_segment"),
grid1.Column("mile_post"),
grid1.Column("", header: "ToEdit", format: @<text>@Html.ActionLink("Edit", "Edit", "Person", new { id = item.ID }, new { target = "_blank" })</text>)));
}
</div>
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
 
 

Answers (3)