Alternative to ViewBag.Title in ASP.NET MVC 3

前端 未结 8 1875
不思量自难忘°
不思量自难忘° 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条回答
  •  旧时难觅i
    2021-02-05 05:22

    For me personally, I think this case is an acceptable use of ViewBag. It is limited to a "well-known" property, and it likely won't cause any problems in the future. In the end, it is all about being pragmatic and finding a way to be as quick as possible. Having a base class where you need to set the title would in my opinion be too much code to be worth the type safety.

    Good luck!

提交回复
热议问题