开发者

helper.Action: problem with formatting an URL based on route values

helper.Action: problem with formatting an URL based on route values

I navigate to a 'detail' page with the id 10.000 as you can see on the picture above.

On this page, I have a back button (named 'retour' in french).

helper.Action: problem with formatting an URL based on route values

I need to form开发者_C百科at the URL for this button to navigate back to the search page.

helper.Action: problem with formatting an URL based on route values

I have an object populated with criteria (picture above). As you can see, IdAffaire is null.

BUT when the URL is formatted with the helper.Action method, the IdAffaire is initialized with the value 10.000 retrieved from the URL of the page!! This is a behaviour of the routing system.

"The routing system is keen to make a match against a route, to the extent that it will reuse segment variable values from the incoming URL."

helper.Action: problem with formatting an URL based on route values

This behaviour is problematic for me. I hope you know what I mean, it is difficult to explain.

Any help is greatly appreciated.

Edit: here is the route causing the problem:

        routes.MapRoute(
        "Affaire Detail",                                               // Route name
        "{controller}/Detail/{IdAffaire}",                              // URL with parameters
        new { action = "Detail" },                                      // Parameter defaults
        new { controller = "Affaire" }                                  // Contraints
        );


That's the default behavior and is by design. You can workaround it by explicitly setting values:

helper.Action("SearchAffaires", "Affaire", new { 
    IdAffaire = "",  
    page = sessionWrapper.SearchCriteriaAffaire.Page, 
    pageSize = sessionWrapper.SearchCriteriaAffaire.PageSize,
    // pass any other parameter that your SearchAffaires action might require
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜