MVC3 RouteUrl inside ViewModel

I need to create a route URL based on parameters as part of the returned JSON values.

What is the equivalent of Url.RouteUrl, but is used inside the controller code, so I can return a string in my Json result that contains routeurl.

I need to do this outside the controller class, in a separate class, can this be done at all?

+6
source share
1 answer

You can still use Url.RouteUrl , but in a slightly different way.

Put using System.Web.Mvc; at the beginning of your class (of course, you may need to add a link to System.Web.Mvc).

Then we get the Url object:

 UrlHelper Url = new UrlHelper(HttpContext.Current.Request.RequestContext); 

and access as usual: Url.RouteUrl .

+12
source

Source: https://habr.com/ru/post/895015/


All Articles