Alternative to ViewBag.Title in ASP.NET MVC 3

前端 未结 8 1855
不思量自难忘°
不思量自难忘° 2021-02-05 05:20

By default the new project template for ASP.NET MVC 3 adds the following to the default layout (masterpage in razor):

@ViewBag.Title
<         


        
8条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 05:44

    we prefer strong title setting.. few sample from our BaseController class. (Page defines encapsulated view modal)

    protected override ViewResult View(string viewName, string masterName, object model)
    {
        if (model is Page)
        {
            ViewBag.Title = ((Page)model).Title;
            //HACK: SEO
            //TODO: SEO
        }
        return base.View(viewName, masterName, model);
    }
    

提交回复
热议问题