0

我在服务器(IIS6)上的路由有问题。它在开发环境中工作正常:

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

我在这里称这个动作:

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

我拥有的所有路线:

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

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

我试过 url: "FindCities.aspx/" + state_id 和 "FindCities.aspx/{state_id}" 和其他变体,但它没有找到正确的方法。为 IIS6 编写路由的正确方法是什么?TIA

4

2 回答 2

0

我写了一个直接的 url,如果你知道如何为 IIS6 写路由请回答

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "Regions.aspx/FindCitiesByStateID/",
            data: 'state_id=' + state_id,
            dataType: "json"
            ...
于 2010-02-10T14:25:30.607 回答
0

@1gn1ter 您是否考虑过在您的 jquery.ajax url 上使用 @Url.Action("") 方法?通过使用 @Url.Action("") 你让它在运行时解析你的整个 url。因此它将在开发和生产环境上匹配。

如果您需要使用该特定路由,您还可以使用 @Url.RouteUrl() 将您的路由名称作为参数传递。

例子

 $("#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  
} 

     }); 
    });
于 2011-09-01T17:25:14.133 回答