开发者

How to write nested functions in UrlHelper?

开发者 https://www.devze.com 2023-03-28 23:27 出处:网络
I\'m writting a UrlHelper and now I need to write a nested function because for example I have page Articles which is accessed for everyone and I have separate Articles in Admin panel.

I'm writting a UrlHelper and now I need to write a nested function because for example I have page Articles which is accessed for everyone and I have separate Articles in Admin panel. First have link: /Articles and next /Admin/Articles.

So I want to use UrlHelper like this:

In public page:

Url.Articles()

In admin page:

Url.Admin.Article开发者_开发知识库()

Please tell me how I can achieve it?


You can implement Url.Admin().Article() by writing an Admin() extension method for the UrlHelper that returns an instance of some class with the Article() method.

However, C# does not support extension properties so the Url.Admin.Article() nested method is not possible without modifying ASP MVC source code.

0

精彩评论

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