开发者

MVC3 RouteUrl inside a ViewModel

开发者 https://www.devze.com 2023-03-28 04:59 出处:网络
I need to create a route URL based on parameters as a part of a JS开发者_如何学GoON return values.

I need to create a route URL based on parameters as a part of a JS开发者_如何学GoON return values.

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

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


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

Place a using System.Web.Mvc; at the top of your class (of course, you might need to Add Reference to System.Web.Mvc).

Then get the Url object by:

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

and access as usual: Url.RouteUrl.

0

精彩评论

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