MVC 3 Razor, Helpers with custom markup/section

前端 未结 4 583
囚心锁ツ
囚心锁ツ 2021-02-05 21:16

I\'m not even sure if this is possible, but I thought I would check to see if there is any way to make this easier.

First, I have some repeated markup in my site that lo

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 21:52

    If you are using Razor and MVC 3 it's real easy to write a quick helper method that would go inside the app_code folder, (I'll name it MyHtmlHelpers)

    I'd try something a little different and a little easier such as:

    @helper myTemplate(string title, string markup){
        

    @title

    @markup
    }

    And the way you use it from a .cshtml file is as followed:

    @MyHtmlHelpers.myTemplate('title','markup')
    

    It should work, if I understand you correctly.

提交回复
热议问题