AspNet.Mvc.TypedRouting icon indicating copy to clipboard operation
AspNet.Mvc.TypedRouting copied to clipboard

How to generate an url from an action with viewmodel

Open valeriob opened this issue 8 years ago • 2 comments

Hi, given an action with a ViewModel parameter public IActionResult Index(IndexViewModel model) and a viewModel like this public class IndexViewModel { public int MyProperty {get;set;} } i would like that var url = Url.Action<HomeController>(r => r.Index(model)); generate /Home/Index?MyProperty=5

How can i do that with TypedRouting ? Thanks

valeriob avatar Jul 25 '17 16:07 valeriob

I am wondering about this as well. This case doesn't appear to work:

public IActionResult Index(int n){ ... }

public IActionResult Redirect(){
    return this.RedirectToAction<HomeController>(a=>a.Index(1));
}

The RedirectToActionResult that is returned contains a null RouteValueDictionary. This works however, but it kinda negates the good part of having typed routing IMHO.

public IActionResult Redirect(){
    return this.RedirectToAction<HomeController>(a=>a.Index(With.No<int>()), new{n=1});
}

svickers avatar Aug 15 '17 17:08 svickers

Hi, thank you for your issue. Since I am overwhelmed with my other project https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc, I did not have a lot of time to support this one. Will try to publish a new package during the weekend. Thank you for your patience!

ivaylokenov avatar Sep 10 '19 13:09 ivaylokenov