【问题标题】:MapRoute problem in ASP.NET MVC (for IIS6)ASP.NET MVC 中的 MapRoute 问题(对于 IIS6)
【发布时间】:2010-02-10 08:24:41
【问题描述】:

我在服务器 (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

【问题讨论】:

    标签: ajax iis-6 asp.net-mvc-routing maproute


    【解决方案1】:

    我写了一个直接的url,如果你知道怎么写IIS6的Routes请回答

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

    【讨论】:

      【解决方案2】:

      @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  
      } 
      
           }); 
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-30
        • 2018-08-08
        • 2016-10-24
        • 2010-09-07
        • 1970-01-01
        • 1970-01-01
        • 2011-02-07
        相关资源
        最近更新 更多