Using a Razor @functions in several webpages (.cshtml files)

前端 未结 3 434
孤独总比滥情好
孤独总比滥情好 2020-12-03 14:13

I have the below function that I would like to be available to several .cshtml views in my asp.net web pages 2 application. How can I make this function available to any vie

3条回答
  •  孤城傲影
    2020-12-03 14:33

    You can define "global" helper functions in a Razor file in the AppCode directory as described here: http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax-within-razor.aspx. However, helpers only render page elements; they cannot return a value (or more correctly, the returned value is the HTML markup to be rendered).

    If you need to return a value, your best bet is an extension method.

提交回复
热议问题