Reputation: 61636
I have the following method in my controller.
[HttpGet]
public ActionResult MyGetMethod(string address, string zip, int width) {...}
It's called via http://foo.com/home/MyGetMethod?address=234MainSt&zip=90210&width=123
Is there a way to combine the parameters address, zip and width into an object and have object be passed in to the method in the following manner?
[HttpGet]
public ActionResult MyGetMethod(Foo myParam) {...}
public class Foo {
public string Address {get; set;}
public string Zip {get; set;}
public int Width {get; set;}
}
There is a vaguely related question for the old ASP.NET MVC that seems to suggest that this is impossible for that technology.
Is it possible with the .NET Core 2.x?
Upvotes: 0
Views: 480
Reputation: 948
your data in queryString so you need provider[FromQuery]
[FromQuery]
[HttpGet]
public ActionResult MyGetMethod([FromQuery]Foo myParam) {...}
public class Foo {
public string Address {get; set;}
public string Zip {get; set;}
public int Width {get; set;}
}
Upvotes: 1