Passing attached properties in asp.net mvc actionlink

My action takes a model that looks like this:

public class ClassListVM { public ClassListVM() { Filter = new ClassFilterModel(); } public ClassFilterModel Filter { get; set; } public PagedList<Class> Classes { get; set; } } public class ClassFilterModel { public int? TermId { get; set; } public int? SubFormId { get; set; } public int? FormId { get; set; } } public ActionResult Index(ClassListVM model) { model.Classes = classService.GetClasses(model.Filter); return View(model); } 

Now I want to generate the url: /Classes?Filter.SubFormId=1 . How to get the Filter part in a URL using this code:

 <a href="@Url.Action("Details", "Classes", new {Filter.TermId = Model.TermId, Filter.SubFormId = subForm.SubFormId})">go</a> 

As you can see, Filter cannot be used here.

+4
source share
1 answer

Theoretically, you can build it like this:

 <a href="@Url.Action("Details", "Classes") ?Filter.TermId=@Model.TermId &amp; Filter.SubFormId=@subForm.SubFormId ">go</a> 

Something like; essentially, insert the query string into the client markup and enter only the parameters.

+1
source

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


All Articles