HttpPost Route breaking Mapping

131 views Asked by At

I have a three tier view path which I am trying to route and map.

[Route("parent", Name = "parent")]
[MvcSiteMapNode(Title = "Parent", ParentKey = "home", Key = "parent")]
public ActionResult parent()
{
    ...............
}

[Route("parent/child/{param}", Name = "child")]
[MvcSiteMapNode(Title = "Child", ParentKey = "parent", Key = "child", PreservedRouteParameters = "param")] 
public ActionResult child(int param)
{
    ..............
}

[Route("parent/child/{param}/{filterparam1 ?}/{filterparam2 ?}")]
[HttpPost]
public ActionResult child(int param, int filterparam1 = 0, int filterparam2 = 0 )
{
    ..............
}

[Route("parent/child/grandchild/{param}/{name}")]
[MvcSiteMapNode(Title = "Grandchild", ParentKey = "child", Key="grandchild", PreservedRouteParameters = "param, name")]
public ActionResult grandchild(int param, string = name)
{
    ..............

    var node = SiteMaps.Current.CurrentNode;
    node.Title = model.name;

    ..............
}

The problem I have is that if I include the [Route] tag on the [HttpPost]:

[Route("parent/child/{param}/{filterparam1 ?}/{filterparam2 ?}")]
[HttpPost]

My postback filter works, but the grandchild does not get included in the routing tree, does not show on my breadcrumb and the node code Errors:

var node = SiteMaps.Current.CurrentNode;
node.Title = model.name;

If however I comment out the [Routing] tag on the [HttpPost] the filter does not work but the grandchild does get routed, appears on my breadcrumb and the node code runs successfully.

Does anyone know what is going on?

1

There are 1 answers

0
Scott On

I worked this out for anyone with the same problem:

I reordered the code in the controller so that all named route came before any posts:

[Route("parent/child/{param}", Name = "child")]
[MvcSiteMapNode(Title = "Child", ParentKey = "parent", Key = "child", PreservedRouteParameters = "param")] 
public ActionResult child(int param)
{
    ..............
}

[Route("parent/child/grandchild/{param}/{name}")]
[MvcSiteMapNode(Title = "Grandchild", ParentKey = "child", Key="grandchild", PreservedRouteParameters = "param, name")]
public ActionResult grandchild(int param, string = name)
{
    ..............

    var node = SiteMaps.Current.CurrentNode;
    node.Title = model.name;

    ..............
}

[Route("parent/child/{param}/{filterparam1 ?}/{filterparam2 ?}")]
[HttpPost]
public ActionResult child(int param, int filterparam1 = 0, int filterparam2 = 0 )
{
    ..............
}