0

I want make page title like "Index-'CategoryName'".I tried use codes like this:

@model PagedList.IPagedList<Article>
@using PagedList.Mvc;
@using PagedList;

@{
    ViewBag.Title = "Index"+@Model.Category.Name;
}

but it didn't work. How can i make page title like "Index-C#" ?? What should i use?

Konamiman
  • 49,681
  • 17
  • 108
  • 138
CoderWho
  • 210
  • 1
  • 5
  • 20
  • 1
    You should try to understand the reason for this behaviour. Take a look at this answer: http://stackoverflow.com/questions/10321902/asp-net-mvc-use-of-in-c-sharp-code-block – Ric Jun 15 '15 at 08:43

3 Answers3

4

Try:

 ViewBag.Title = "Index" + Model.Category.Name;
Joe
  • 122,218
  • 32
  • 205
  • 338
4

You should reference your model as just Model, not @Model. The @ character is used in order to start writing code when you are in the middle of the HTML markup, but in this case you are already inside a code block (started with @{ in the previous line).

Konamiman
  • 49,681
  • 17
  • 108
  • 138
2

Just like this:

ViewBag.Title = "Index" + Model.Category.Name;

Without the @.

Here are some links helping you to understand when/where to use @:

http://weblogs.asp.net/scottgu/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax

http://odetocode.com/blogs/scott/archive/2013/01/09/ten-tricks-for-razor-views.aspx

Razvan Dumitru
  • 11,815
  • 5
  • 34
  • 54