strange behivour with routing

Last post 07-05-2008 4:06 AM by panjkov. 4 replies.

Sort Posts:

  • strange behivour with routing

    07-05-2008, 3:31 AM
    • Loading...
    • Ahtesham
    • Joined on 04-09-2008, 12:00 PM
    • Posts 85

    there is strange behviur with routing , i do not know that am i doing wrong and what i am doing wrong

    i am calling a action in a controller when i call it with id it works but when i try to call it without id it do not work

    origanlly my global file was like this

    routes.MapRoute(

    "Default", // Route name

    "{controller}/{action}/{id}", // URL with parameters

    new { controller = "Home", action = "Index", id = "" } // Parameter defaults

    );

    routes.MapRoute(

    "Default2", // Route name

    "admin/manufecturer/Edit/{id}", // URL with parameters

    new { controller = "manufecturer", action = "Edit", id = "" }, // Parameter defaults

    new { controller = @"[^\.]*" });

    routes.MapRoute(

    "Default21", // Route name

    "admin/manufecturer/New/{id}", // URL with parameters

    new { controller = "manufecturer", action = "New", id = "" }, // Parameter defaults

    new { controller = @"[^\.]*" });

     

    but i also tried that with other variation too

    routes.MapRoute(

    "Default", // Route name

    "{controller}/{action}/{id}", // URL with parameters

    new { controller = "Home", action = "Index", id = "" } // Parameter defaults

    );

    routes.MapRoute(

    "Default2", // Route name

    "admin/manufecturer/Edit/{id}", // URL with parameters

    new { controller = "manufecturer", action = "Edit", id = "" }, // Parameter defaults

    new { controller = @"[^\.]*" });

    routes.MapRoute(

    "Default21", // Route name

    "admin/manufecturer/New/", // URL with parameters

    new { controller = "manufecturer", action = "New" }, // Parameter defaults

    new { controller = @"[^\.]*" });

    but without id its not workin , what i am missing ,

    Ahtesham

  • Re: strange behivour with routing

    07-05-2008, 3:38 AM
    Answer
    • Loading...
    • panjkov
    • Joined on 01-12-2003, 12:16 AM
    • Banjaluka, Bosnia and Herzegovina
    • Posts 127

     On your action methods in controller, id need to be nullable

    Dragan Panjkov
    [http://blogpanjkov.qsh.eu/] [http://panjkov.qsh.eu/]

  • Re: strange behivour with routing

    07-05-2008, 3:39 AM
    • Loading...
    • panjkov
    • Joined on 01-12-2003, 12:16 AM
    • Banjaluka, Bosnia and Herzegovina
    • Posts 127

     and in your route table, always set Default route as last in the list.

    Dragan Panjkov
    [http://blogpanjkov.qsh.eu/] [http://panjkov.qsh.eu/]

  • Re: strange behivour with routing

    07-05-2008, 4:01 AM
    • Loading...
    • Ahtesham
    • Joined on 04-09-2008, 12:00 PM
    • Posts 85

    why is that when i put null in id it works

    routes.MapRoute(

    "Default2", // Route name

    "admin/manufecturer/Edit/{id}", // URL with parameters

    new { controller = "manufecturer", action = "Edit", id = (string)null }, // Parameter defaults

    new { controller = @"[^\.]*" });

    routes.MapRoute(

    "Default21", // Route name

    "admin/manufecturer/New/{id}", // URL with parameters

    new { controller = "manufecturer", action = "New", id = (string)null }, // Parameter defaults

    new { controller = @"[^\.]*" });

    routes.MapRoute(

    "Default", // Route name

    "{controller}/{action}/{id}", // URL with parameters

    new { controller = "Home", action = "Index", id = (string)null } // Parameter defaults

    );

    why it didnt work with id=""

    Ahtesham

  • Re: strange behivour with routing

    07-05-2008, 4:06 AM
    • Loading...
    • panjkov
    • Joined on 01-12-2003, 12:16 AM
    • Banjaluka, Bosnia and Herzegovina
    • Posts 127

     Not exactly what I meant. I mean

    public ActionResult SomeAction(int? id) {

     // Do something

    }

    what parameters does your controller actions receive?

    Dragan Panjkov
    [http://blogpanjkov.qsh.eu/] [http://panjkov.qsh.eu/]

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter