ASP.NET MVC 中的 MapRoute 问题(针对 IIS6)

发布于 2024-08-21 01:50:40 字数 976 浏览 9 评论 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

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: "application/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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囚你心 2024-08-28 01:50:40

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

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

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"
            ...
哆兒滾 2024-08-28 01:50:40

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

     }); 
    });

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

     }); 
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文