Search code examples
c#.netasp.net-mvcviewbagpage-title

Viewbag.title like "String Title"+@model.name is it possible?


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?


Solution

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