使用“取消”按钮时的ASP.NET MVC路由

问题描述

我正在整个Web应用程序中使用ParentChild路由模式,该模式将具有类似此类的Urls。

使用ParentChild MapRoute可以大大简化整个应用程序中的控制器方法。

https://localhost:44307/ProjectTestEvents/549084af-0e7a-4d2d-a709-04c599ca778e/Details/895d72c1-f667-49d8-b487-5705931b82c9

RouteConfig.cs

routes.MapRoute(
            name: "ParentChild",url: "{controller}/{parentid}/{action}/{childid}",defaults: new { controller = "Login",action = "Index",parentid = UrlParameter.Optional,childid = UrlParameter.Optional
            }
        );

控制器方法:

public ActionResult Details(GenericParentChildModel ParentChild)
{
    // do some stuff ...
}

模型类:

public class GenericParentChildModel
{
    public Guid ParentId { get; set; }
    public string ParentDescription { get; set; }
    public Guid ChildId {get; set; }
    public string ChildDescription { get; set; }
}

当用户选择表单的“取消”按钮并且导航被重定向到上一点时,我想采用相同的方法。

在表单上,​​我有一个“取消”按钮,该按钮调用包含RedirectToAction的通用Return方法。

public ActionResult Return(GenericParentChildModel ParentChild)
{
    return RedirectToAction("Details",new RouteValueDictionary(
               new { controller = "ProjectTestEvents",action = "Details",parentid = ParentChild.ParentId,childid = ParentChild.ChildId }));
}

Url将导致具有querystring参数的Url ...

https://localhost:44307/ProjectTestEvents/Details?parentid=549084af-0e7a-4d2d-a709-04c599ca778e&childid=76bd0fd7-fd4f-4ff1-b357-8a2acc8c6ff7

代替所需的ParentChild格式。

https://localhost:44307/ProjectTestEvents/549084af-0e7a-4d2d-a709-04c599ca778e/Details/895d72c1-f667-49d8-b487-5705931b82c9

查询字符串版本有效,但我宁愿保留用户最初访问该路径时使用的url结构。

任何建议表示赞赏

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)