1

如何使用我的扩展程序创建正确的 MapRoute?(例如“我的”)。这个 MapRoute 是正确的

    routes.MapRoute(
        name: "Default",
        url: "{controller}.my/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );

但我想使用controller.my?id。这个 MapRoute 是错误的

routes.MapRoute(
    name: "",
    url: "{controller}.my/{tid}",
    defaults: new { controller = "Home", action = "Index", tid = UrlParameter.Optional }
);
4

1 回答 1

0

我认为,如果在 MapRoute 中添加参数,就不能简单地将它们用作查询字符串。

从 MapRoute 中删除您希望将它们用作查询字符串的那些参数,并在操作方法中简单地使用它们:

routes.MapRoute(
    name: "",
    url: "{controller}.my",
    defaults: new { controller = "Home", action = "Index" }
);

动作方法:

public ActionResult Index(string tid) // or int tid ...
{
    // ...
}

所以你可以通过类似的方式访问它~/Home.my?tid=someThing

于 2013-08-26T08:04:57.323 回答