I would like to imitate after the controller binding process and bind the query string into a model but not via controller.
I have access to Request.QueryString
from type NameValueCollection
.
How can i force it to get bind the same as mvc4 binding the models via the controller.
For example i have this class:
public class Example
{
public string Name {get;set;}
public string LastName {get;set;}
}
and NameValueCollection(Request.QueryString)
that created by the Request object from the url that is look like ?Name=James&Lastname=Bow
.
Any suggestions?
Why not create an ActionFilter then override the OnActionExecuted method. ActionExecutedContext would have access to Request.QueryString. You can then populate the filterContext.Controller.ViewData.Model from the query string.