开发者

Is is possible to make helpers private in WebMatrix?

开发者 https://www.devze.com 2023-02-08 14:24 出处:网络
I\'ve created my own data grid helper in WebMatrix.The paging and sorting links are helpers too, but I don\'t really want to expose those helpers publicly to the rest of the app.

I've created my own data grid helper in WebMatrix. The paging and sorting links are helpers too, but I don't really want to expose those helpers publicly to the rest of the app.

For example:

@helper Pager(IEnumerable<dynamic> gridData,
    int totalRows, int currentPage, int rowsPerPage)
{
    // Helper code is here.
}

Is there any way 开发者_如何学编程to make a helper private? Would that be a bad practice, anyway? I know there are private functions, but helpers are handy from a syntactic standpoint.


Using the @helper syntax means that your helper method will automatically get compiled to a public static method. So the answer to your question is no.


One way is to create a library and reference it in your web.config or .cshtml file. helpers bascially output the html you need/want, essentially htmlhelpers return an html string. You would have to move all your code out into the library and its separate from your main app.

0

精彩评论

暂无评论...
验证码 换一张
取 消