Can I have a global razor @helper outside of App_Code?

前端 未结 4 1647
轻奢々
轻奢々 2021-01-01 14:39

The question is simple as stated in the title: Is there a way of having razor helpers outside of \'App_Code\'?

Example ( HtmlEx.cshtml file ):

@hel         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 15:00

    sure, you can put them anywhere in your code or project structure. in the file where you create your helper be sure to include using System.Web.Mvc.

    then just normally extend the Helper class like this:

    namespace System.Web.Mvc
    {
        static class HtmlHelperExtensions
        {
            public static IHtmlString MyNewHelper(this HtmlHelper helper, string someParam)
            {
                // do something
            }
        }
    }
    

提交回复
热议问题