Partial View MVC 5 : "A space or line break was encountered after the "@" character

10.2k views Asked by At

Here is the error:

"A space or line break was encountered after the "@" character. Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.

I am using MVC 5 and working through the book Pro ASP.NET MVC 5 - Adam Freeman. Here is the List.cshtml.

Main view

@model SS.WebUI.Models.ProductsListViewModel
@{
    ViewBag.Title = "Products";
}

@foreach (var p in Model.Products) 
{
    @Html.Partial("ProductSummary", p)
}

<div class="pager">
    @Html.PageLinks((SS.WebUI.Models.PagingInfo)Model.PagingInfo, x => Url.Action("List", new { page = x }))
</div>

Partial view

@model SS.Domain.Entities.Product
<div class="well">
  <h3><strong>@Model.Name</strong>
    <span class="pull-right label labelprimary"> @ Model.Price.ToString("c") </span>
  </h3>
  <span class="lead"> @Model.Description</span>
</div> 

I have tried various syntaxes and cannot get it to work - any help will be apprecaited!

1

There are 1 answers

0
Ravi On BEST ANSWER

Most probably you check your partial view code: @ Model.Price.ToString("c")

There is space after @ for Model.Price.. @ Model.Price.ToString("c") --> @Model.Price.ToString("c")