I have the following block of Razor markup:
@section StoreSearch
{
@Html.Partial("SearchPartial", Model)
}
<section id="gallery-index">
...
</section>
<nav class="pager">
<a href="#" rel="prev" class="pager-nav" title="Previous Page">Prev</a> Page @(Model.PageIndex + 1) of @Model.PageCount <a href="#" rel ="next" class="pager-nav" title="Next Page">Next</a>
</nav>
I would like to surround this whole block with a form, as in
@using (Html.BeginForm("Index", "Gallery", FormMethod.Post, new { id = "search-form" }))
{
@section StoreSearch
{
@Html.Partial("SearchPartial", Model)
}
<section id="gallery-index">
...
}
Yet when I do that, the parser seems to balk at the @section StoreSearch part, and complains “Cannot resolve symbol StoreSearch”.
Is what I’m trying to do not allowed, or am I just missing some sort of escaping method?
Looks like you found a bug in the Razor parsing engine. Most likely the first @ sign in a using clause is being parsed as a variable, which in your case is actually a function so it’s throwing an exception. For now the solution is to surround your section with a
div(or any html element really).