asp.net - ActionResult parameter coming in as null -


i have seen couple related questions this, cannot seem solve exact instance. have url such http://127.0.0.1/uts/unit/j0000001. is, controller uts, action unit , there optional parameter c_number.

i have route configured follows:

  routes.maproute(     name: "unit",     url: "{controller}/{action}/{c_number}",     defaults: new { controller = "uts", action = "unit", c_number = "" }   ); 

then, action in controller as:

    public actionresult unit(string c_number)     {         unitviewmodel uvm = new unitviewmodel();         uvm.unit = pacificrepo.units.firstordefault(g => g.c_number == c_number);         uvm.geolocation = pacificrepo.geolocations.firstordefault(g => g.geo_location.latitude == uvm.unit.geo_location.latitude && g.geo_location.longitude == uvm.unit.geo_location.longitude);         return view(uvm);     } 

whenever go example url gave above, c_number comes null. should j0000001. see blatantly obvious i'm missing?

since define in route don't need add parameter c_number.you can value routedata dictionary.that c_number parameter has value if pass querystring http://someurl.com/uts/unit?c_number="j0000001"

public actionresult unit() {     var cnumber = routedata.values["c_number"].tostring(); } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -