How can I write dynamic data to page layout in MVC 3 Razor?

前端 未结 2 541
眼角桃花
眼角桃花 2021-02-02 14:44

I have MVC 3 C# project with Razor engine. What are the ways and, I guess, the best practices to write dynamic data to the _Layout.cshtml?

For example, maybe I\'d like

2条回答
  •  礼貌的吻别
    2021-02-02 15:03

    In addition to atbebtg's answer, to render stuff into the head, you want to leverage Razor's section support. Sections are named fragments of templated HTML that can be defined in views and rendered in the layout, where the layout sees fit. In the layout, you call @RenderSection("wellKnownSectionName") and in the view that uses the layout, you declare @section wellKnownSectionName {

提交回复
热议问题