4

In MVC5 we can generate fully qualified action method URL from viewmodels using UrlHelper action method like

UrlHelper urlHelper = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);
string url = urlHelper.Action("Index", "Home");

Since we don't have System.Web in ASP.NET 5, how can we generate url's in viewmodels in MVC 6. How do I pass "IScopedInstance" and "IActionSelector" objects when creating instance of UrlHelper?

Prashant
  • 86
  • 1
  • 5
  • 3
    possible duplicate of [Unable to utilize UrlHelper](http://stackoverflow.com/questions/30696337/unable-to-utilize-urlhelper) – Daniel J.G. Jun 08 '15 at 09:42
  • 1
    @DanielJ.G. I see we can use Url property of Controller, httpcontext property in controller or using dependency injection(as you mentioned in the link) and generate URL's in controllers and filters, but how can we achieve the same in models/viewmodels like generating link in either constructor or property of model class. Am I missing anything here? – Prashant Jun 09 '15 at 02:32
  • 1
    Generally I would set values in the model/viewModel from a controller/service/mapper class which would use the UrlHelper. If you must generate the url inside the model/viewModel, you can pass the UrlHelper in its constructor – Daniel J.G. Jun 09 '15 at 08:07

0 Answers0