views:

34

answers:

2

Hi guys, now a days i m having hell a lot of trouble using routing infrastructure of asp.net mvc2. i have following routes registered in my global.asax file

routes.MapRoute(
              "strict",
              "{controller}.mvc/{docid}/{action}/{id}",
              new { action = "Index", id = "", docid = "" },
              new { docid = @"\d+"}

            );
 routes.MapRoute(
              "default",
              "{controller}.mvc/{action}/{id}",
              new { action = "Index", id = "" },
              new { docConstraint = new DocumentConstraint() }
            ); 

the problem is with first route ("strict"). three kind of urls can match first route. mycontroller/23/myaction,mycontroller/23/myaction/12 or mycontroller/23/mvaction/stringid. if i try to use this route without specifying value of id everything works fine for example

Html.ActionLink("Link text", "ActionName", new{docid = 23});

every thing goes well. but if i use links like

  Html.ActionLink("Link text", "ActionName", new{docid = 23, id = 223})

this will produce url currentcontroller.mvc/23/ActionName/223 that is absolutely correct but when it loads the page it gives javascript error in jquery1.4.2.min.js file. well this is strange. if i change id to someid =223 it will reflect in query string and there will be no js error; even stranger. can anyone help me in solving this annoying problem.

Edit: i have done some further debugging and found when both id and docid are mentioned in route values one thing is ignored in global.asax that is the ignore path

routes.RouteExistingFiles = false;
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.ignoreRoute is totally by passed and i can c names of js files in route value dictionary while debugging in my controller.

regards
adeel

A: 

it gives javascript error in jquery1.4.2.min.js file

The most likely cause for this is that something you are displaying on the page is different and you are performing an action that is causing the error. Can you supply enough of a sample from the rendered page to show what you are using jQuery for?

Sohnee
Problem may not be related to javascript. as i mentioned in my question as i use id parameter along with the docid parameter the error occurred. if i change id to someid(or whatever) everything works fine. I think (i may be wrong) problem occured when "{controller}.mvc/{docid}/{action}/{id}" is matched
Muhammad Adeel Zahid
@Sohnee i have done some debugging and updated the question plz c if u can help me here regards
Muhammad Adeel Zahid
A: 

if we drag scripts from solution explorer to site.master it results in following output

<script type="text/javscript" src="../../scripts/jquery.min.js"></script> 

leading dots (..) are creating the problem. putting source path in url.content or using /scripts instead of ../../scripts will solve the problem because these leading periods are forcing them to match some route in global.asax
regards
adeel

Muhammad Adeel Zahid