1

I am facing the issue with routes and showing exception. it is due to when parameters are null or blank - here when title is blank then issue.

Issue URL : http://{ParentURL}/Admin/Menu/AddEdit/299921b2-3d7b-4e0a-b23e-5838f9b78654/1 - when Title is blank

Working Fine URL : http://{ParentURL}/Admin/Menu/AddEdit/Test/299921b2-3d7b-4e0a-b23e-5838f9b78654/1 -> Here Test Is Title

context.MapRoute(
                    "AdminOperation",
                    "Admin/{controller}/{action}/{title}/{id}/{pageno}",
                    new { action = "AddEdit", id = UrlParameter.Optional, pageno = UrlParameter.Optional, title = UrlParameter.Optional }
                );

//controller method

public ActionResult AddEdit(string id,  string title, int? pageno)
{
}

please help me on it.

Regards

4
  • can you show your controller code?
    – ssilas777
    Aug 18, 2013 at 13:32
  • added controller method Aug 18, 2013 at 13:40
  • The title will not be blank in the "Issue URL", it will be bound to "299921b2-3d7b-4e0a-b23e-5838f9b78654". Route placeholders are matched simply on the order of the values in the incoming URL. Are you asking how to handle the error of the missing value or are you asking why the value is missing from the URL? Aug 18, 2013 at 14:40
  • I am askineg if Title is blank then , how to manage with mentioned route without creating new one? Aug 19, 2013 at 8:05

1 Answer 1

1

If title sometimes may be null, to my mind, a better approach will be to add one more route without it and place it before the route you mentioned:

context.MapRoute(
           "AdminOperationShort",
           "Admin/{controller}/{action}/{id}/{pageno}",
         new { action = "AddEdit", id = UrlParameter.Optional, pageno = UrlParameter.Optional});  


     context.MapRoute(
           "AdminOperation",
           "Admin/{controller}/{action}/{title}/{id}/{pageno}",
           new { action = "AddEdit", id = UrlParameter.Optional, pageno = UrlParameter.Optional, title = UrlParameter.Optional }
                        );
1
  • Here using your way it will showing title value of Id in controller method instead of title need to show blank. Aug 19, 2013 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.