Viewbag.title like "String Title"[email protected] is it possible?

1.7k views Asked by At

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"[email protected];
}

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

3

There are 3 answers

0
Konamiman On BEST ANSWER

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).

0
Joe On

Try:

 ViewBag.Title = "Index" + Model.Category.Name;
0
Razvan Dumitru On

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