asp.net - How do QueryString parameters get bound to Action method parameters? -


i have webforms project, , attempting run code allows me make call mvc route , render result within body of web forms page.

there couple of httpresponse/request/context wrappers use execute call mvc route, e.g.:

private static string renderinternal(string path) {   var responsewriter = new stringwriter();    var mvcresponse = new mvcplayerhttpresponsewrapper(responsewriter, pagerenderer.currentpageid);   var mvcrequest = new mvcplayerhttprequestwrapper(request, path);   var mvccontext = new mvcplayerhttpcontextwrapper(context, mvcresponse, mvcrequest);    lock (httpcontext.current)   {     new mvchttphandlerwrapper().publicprocessrequest(mvccontext);   }    ... 

the code works fine executing simple mvc routes, e.g. "/home/index". can't specify query string parameters (e.g. "/home/index?foo=bar") ignored. have tried set querystring directly within requestwrapper instance, so:

public class mvcplayerhttprequestwrapper : httprequestwrapper {   private readonly string _path;   private readonly namevaluecollection query = new namevaluecollection();    public mvcplayerhttprequestwrapper(httprequest httprequest, string path)     : base(httprequest)   {     var parts = path.split('?');      if (parts.length > 1)     {       query = extractquerystring(parts[1]);     }      _path = parts[0];   }    public override string path   {         {       return _path;     }   }    public override namevaluecollection querystring   {         {       return query;     }   }    ... 

when debugging can see correct values in "request.querystring", values never bound method parameter.

does know how querystring values used , bound http request mvc controller action?

it seems handling of querystring value more complex anticipated. have limited knowledge of internals of mvc request pipeline.

i have been trying research internals myself , continue so. if find update post appropriately.

i have created simple web forms project containing code needed produce problem , have shared via dropbox: https://www.dropbox.com/s/vi6erzw24813zq1/stackmvcgetquestion.zip project contains 1 default.aspx page, controller, , mvcwrapper class used render out result of mvc path. if @ default.aspx.cs see route path containing querystring parameter passed in, never binds against parameter on action.

as quick reference, here extracts web project.

the controller:

public class homecontroller : controller {   public actionresult index(string foo)   {     return content(string.format("<p>foo = {0}</p>", foo));   } } 

the default.aspx page:

protected void page_load(object sender, eventargs e) {   string path = "/home/index?foo=baz";    divmvcoutput.innerhtml = mvcwrapper.mvcplayerfunctions.render(path); } 

i have been struggling quite while now, appreciate advice in form. :)

mvc framework try fill values of parameters of action method query string (and other available data such posted form fields, etc.), part got right. part missed matching name of parameter value names passed in. if have method mymethod in controller mycontroller signature:

public actionresult mymethod(string path) {     //some code goes here } 

the query string (or 1 of other sources of variables) must contain variable named "path" framework able detect it. query string should /mycontroller/mymethod?path=baz


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -