Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用“从取消”按钮时的ASP.NET MVC路由_C#_Asp.net Mvc_Url Routing - Fatal编程技术网

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

C# 使用“从取消”按钮时的ASP.NET MVC路由,c#,asp.net-mvc,url-routing,C#,Asp.net Mvc,Url Routing,我在整个web应用程序中使用ParentChild路由模式,该模式将具有如下URL 使用ParentChild MapRoute可以大大简化整个应用程序中的控制器方法 https://localhost:44307/ProjectTestEvents/549084af-0e7a-4d2d-a709-04c599ca778e/Details/895d72c1-f667-49d8-b487-5705931b82c9 RouteConfig.cs routes.MapRoute(

我在整个web应用程序中使用ParentChild路由模式,该模式将具有如下URL

使用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; }
}
当用户选择表单的“取消”按钮并且导航被重定向到上一点时,我希望应用相同的方法

在表单上,我有一个Cancel按钮,它调用一个包含RedirectToAction的通用返回方法

public ActionResult Return(GenericParentChildModel ParentChild)
{
    return RedirectToAction("Details", new RouteValueDictionary(
               new { controller = "ProjectTestEvents", action = "Details", 
                    parentid = ParentChild.ParentId, 
                    childid = ParentChild.ChildId }));
}
该Url将生成一个带有查询字符串参数的Url

https://localhost:44307/ProjectTestEvents/Details?parentid=549084af-0e7a-4d2d-a709-04c599ca778e&childid=76bd0fd7-fd4f-4ff1-b357-8a2acc8c6ff7
而不是所需的父子格式

https://localhost:44307/ProjectTestEvents/549084af-0e7a-4d2d-a709-04c599ca778e/Details/895d72c1-f667-49d8-b487-5705931b82c9
查询字符串版本可以工作,但我宁愿保留用户最初访问该路径时使用的url结构

感谢您的任何建议

为什么您不能更改

url: "{controller}/{parentid}/{action}/{childid}"

或添加路由属性

[Route("~/ProjectTestEvents/Details/{parentid}/{childid}
public ActionResult Details(GenericParentChildModel ParentChild)

[Route("~/ProjectTestEvents/Details/{parentid}/{childid}
public ActionResult Details(GenericParentChildModel ParentChild)