ivaylokenov / AspNet.Mvc.TypedRouting

A collection of extension methods providing strongly typed routing and link generation for ASP.NET Core MVC projects.
https://mytestedasp.net/
MIT License
485 stars 36 forks source link

How to generate an url from an action with viewmodel #32

Open valeriob opened 7 years ago

valeriob commented 7 years ago

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(r => r.Index(model)); generate /Home/Index?MyProperty=5

How can i do that with TypedRouting ? Thanks

svickers commented 7 years ago

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});
}
ivaylokenov commented 5 years ago

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!