routing paramenter returns null when only supplying first paramenter in MVC
        Posted  
        
            by 
                Ray ForRespect
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Ray ForRespect
        
        
        
        Published on 2012-11-14T04:58:13Z
        Indexed on 
            2012/11/14
            4:59 UTC
        
        
        Read the original article
        Hit count: 265
        
My issue is that I customer Map Route in MVC which takes three parameters. When I supply all three or just two, the parameters are passed from the URL to my controller. However, when I only supply the first parameter, it is not passed and returns null. Not sure what causes this behavior.
Route:
        routes.MapRoute(
            name: "Details",                                              // Route name
            url: "{controller}/{action}/{param1}/{param2}/{param3}",                           // URL with parameters
            defaults: new { controller = "Details", action = "Index", param1 = UrlParameter.Optional, param2 = UrlParameter.Optional, param3 = UrlParameter.Optional }  // Parameter defaults
         );
Controller:
    public ActionResult Map(string param1, string param2, string param3)
    {
        StoreMap makeMap = new StoreMap();
        var storemap = makeMap.makeStoreMap(param1, param2, param3);
        var model = storemap;
        return View(model);
    }
string param1 returns null when I navigate to:
/StoreMap/Map/PARAM1NAME
but it doesn't return null when I navigate to:
/StoreMap/Map/PARAM1NAME/PARAM2NAME
© Stack Overflow or respective owner