Is is possible to make helpers private in WebMatrix?
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.
精彩评论