Query string parameter name different than model property name
up vote
1
down vote
favorite
Have a basic search form. Is there something built into the MVC model binder that can take a different (shorter) name of the parameter and bind it with the desired model property?
For instance I want fn
instead of SearchFirstName
to appear in the address bar.
Model:
public class SampleModel
public string SearchFirstName get; set;
Controller:
public ActionResult Search([FromUri] SampleModel model)
Sending /search?fn=foo
makes SearchFirstName=foo
I know I can do something manually within the controller property by property but don't want to reinvent the wheel if it's built in already.
Using .NET framework 4.6.1
asp.net-mvc model-binding
add a comment |
up vote
1
down vote
favorite
Have a basic search form. Is there something built into the MVC model binder that can take a different (shorter) name of the parameter and bind it with the desired model property?
For instance I want fn
instead of SearchFirstName
to appear in the address bar.
Model:
public class SampleModel
public string SearchFirstName get; set;
Controller:
public ActionResult Search([FromUri] SampleModel model)
Sending /search?fn=foo
makes SearchFirstName=foo
I know I can do something manually within the controller property by property but don't want to reinvent the wheel if it's built in already.
Using .NET framework 4.6.1
asp.net-mvc model-binding
You would need to create a custom ModelBinder to read the value from the request and set the property of your model.
– Stephen Muecke
Nov 8 at 21:04
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Have a basic search form. Is there something built into the MVC model binder that can take a different (shorter) name of the parameter and bind it with the desired model property?
For instance I want fn
instead of SearchFirstName
to appear in the address bar.
Model:
public class SampleModel
public string SearchFirstName get; set;
Controller:
public ActionResult Search([FromUri] SampleModel model)
Sending /search?fn=foo
makes SearchFirstName=foo
I know I can do something manually within the controller property by property but don't want to reinvent the wheel if it's built in already.
Using .NET framework 4.6.1
asp.net-mvc model-binding
Have a basic search form. Is there something built into the MVC model binder that can take a different (shorter) name of the parameter and bind it with the desired model property?
For instance I want fn
instead of SearchFirstName
to appear in the address bar.
Model:
public class SampleModel
public string SearchFirstName get; set;
Controller:
public ActionResult Search([FromUri] SampleModel model)
Sending /search?fn=foo
makes SearchFirstName=foo
I know I can do something manually within the controller property by property but don't want to reinvent the wheel if it's built in already.
Using .NET framework 4.6.1
asp.net-mvc model-binding
asp.net-mvc model-binding
asked Nov 8 at 20:15
joym8
1,61022145
1,61022145
You would need to create a custom ModelBinder to read the value from the request and set the property of your model.
– Stephen Muecke
Nov 8 at 21:04
add a comment |
You would need to create a custom ModelBinder to read the value from the request and set the property of your model.
– Stephen Muecke
Nov 8 at 21:04
You would need to create a custom ModelBinder to read the value from the request and set the property of your model.
– Stephen Muecke
Nov 8 at 21:04
You would need to create a custom ModelBinder to read the value from the request and set the property of your model.
– Stephen Muecke
Nov 8 at 21:04
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53215475%2fquery-string-parameter-name-different-than-model-property-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You would need to create a custom ModelBinder to read the value from the request and set the property of your model.
– Stephen Muecke
Nov 8 at 21:04