I am very new to MVC and I am updating a web form application to mvc. I have a shared layout (masterpage in webforms), I would like to set the meta and title information per vie
I like to set page titles dynamically using the action and controller names. You can use a library like Humanizer to convert "SomeActionName" into "Some action name":
public static class HtmlHelperExtensions
{
public static MvcHtmlString GetPageTitle(this HtmlHelper helper)
{
var actionName = helper.GetRouteDataValue("action");
var controllerName = helper.GetRouteDataValue("controller");
return new MvcHtmlString(controllerName.Humanize() + " - " + actionName.Humanize());
}
private static string GetRouteDataValue(this HtmlHelper helper, string value)
{
return helper.ViewContext.RouteData.Values[value].ToString();
}
}
and then in your _Layout:
@Html.GetPageTitle()