开发者

MapRoute problem in ASP.NET MVC (for IIS6)

I have a problem in routing on the server (IIS6). It works OK on the development environment:

routes.MapRoute(
       "FindCities", 
       "FindCities/{state_id}",
        new { controller = "Regions", action = "FindCitiesByStateID", state_id = "" });

Here I call this action:

   $.ajax({
            type: "GET",
            contentType: "applic开发者_如何学JAVAation/json; charset=utf-8",
            url: "FindCities/" + state_id,
            data: "{}",
            dataType: "json" 
            ...

All routes i have:

            routes.MapRoute(
                "Default",
                "{controller}.aspx/{action}/{id}",
                new { action = "Index", id = "" }
              );

            routes.MapRoute(
              "Root",
              "",
              new { controller = "Home", action = "Index", id = "" }
            );

I've tried url: "FindCities.aspx/" + state_id and "FindCities.aspx/{state_id}" and other variants, but it doesn't find the right way. What is the right way to write routes for IIS6? TIA


I've written a direct url, if you know how to write Routes for IIS6 please answer

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "Regions.aspx/FindCitiesByStateID/",
            data: 'state_id=' + state_id,
            dataType: "json"
            ...


@1gn1ter have you considered using on you jquery.ajax url the @Url.Action("") method? By using @Url.Action("") you let it resolve your entire url on runtime. Thus it will match both on development and production environment.

If you need to use that specific route, you can also use @Url.RouteUrl() passing your route name as a parameter.

EXAMPLE

 $("#something").click(function(){

    var values = {cityId: $("#txtCity").val() }

    $.ajax({    
         //Other ajax definitions like type, content, datatype, etc

         url: '@Url.Action("YourActionName", "YourControllerName")',    
         data: values, 


     success: function(data){    
//Do something    
},    
             error: function(x, y, z){    
//Something bad happened  
} 

     }); 
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜