In ASP.NET MVC 5, I used a basic ViewPage with several properties:
public String PageTitle { get; set; } public String PageDescription { get; set; } public String[] BodyCssClasses { get; set; }
Then on each performance I would:
@{ PageTitle = "Title ..." PageDescription" = "Description ..." BodyCssClasses = new String[] { "main", "home" } }
On the main page, I would just use something like:
<title>@Title</title>
With this approach, I was able to use Strong Typed for page properties ...
Can I use the base view page in ASP.NET MVC 6?
Since there is no Web.Config, how can this be done?
Any suggestions on the best options for defining page information are welcome.
UPDATE
I followed the suggestion and I use:
public abstract class ViewPageBase<TModel> : RazorPage<TModel> { public String Title { get; set; } }
Then on _ViewImports I have:
@inherits ViewPageBase<TModel>
In _Layout.cshtml I have:
<title>@Title</title>
And finally, on the view that uses this layout, I:
@{ Title = "Page Title"; Layout = "_Layout"; }
Everything compiles and starts, but the page title is always empty.
Does anyone know why?
asp.net-mvc asp.net-core-mvc
Miguel moura
source share