Shared MVC Razor functions in several views

后端 未结 3 1651
眼角桃花
眼角桃花 2021-02-02 07:23

I have functions in my view that is shared by several pages:

@functions 
{
    public HtmlString ModeImage(ModeEnum mode) 
    {
        switch(mode)
        {
          


        
3条回答
  •  我在风中等你
    2021-02-02 08:16

    This sounds like you want the Razor @helper methods described in the blog post ASP.NET MVC3 and the @helper syntax within Razor by Scott Guthrie.

    Here is the overview... "The @helper syntax within Razor enables you to easily create re-usable helper methods that can encapsulate output functionality within your view templates. They enable better code reuse, and can also facilitate more readable code."

提交回复
热议问题