开发者

ASP.NET MVC 2 Point Return Links to Appropriate View

开发者 https://www.devze.com 2023-01-17 14:32 出处:网络
The default scaffolded views generated by ASP.NET MVC 2 contain links such as: <%: Html.ActionLink(\"Back to List\", \"Index\") %>

The default scaffolded views generated by ASP.NET MVC 2 contain links such as:

<%: Html.ActionLink("Back to List", "Index") %>
<%: Html.ActionLink("Create New", "Create") %>

These links are perfect if I came to this page from that same root. But for example, if I have Orders and Persons and I navigate to /Orders/Edit/17 via /Persons/Orders/3, then 'back to list' returns me to Orders root not Persons root, where I want to go, because the 'Edit Orders' view only knows about orders. This makes the navigation awkward and breaks the flow..

I want to reuse the same 'Edit Orders' vie开发者_如何学Gow regardless of where I came from, but I'm not sure how to pass this information.

I know it's possible to pass parameters like /Orders/Edit/17?myparam=myvalue but will this limit my choices later on if I need to pass parameters which indicate Sort/Filter order for grids?

What is the preferred way to pass a return/origin location to my view so that it can render the links properly? Otherwise, how can I call the view differently from the controller?

EDIT:

For a clean solution, see THIS POST


Passing in parameters through the querystring will not really limit you as long as you don't use the same names. There is a size restriction on querystrings, but you'll probably not hit it.

That's basically how I do it. I'm curious to see what others answer.


This functionality seems like something that should have been accounted for in the framework; it seems fairly hacky to have to specify these parameters because you'd have to do so for every level of navigation.

Why? back is something that belongs in browsers, along with history. Its been like that for a while, why should the framework need to handle that?

What you need its not the norm.

Additionally, you are responsible to keep your code dry. You can definitely handle it in a way that all the repetition you have is the name of the function you are calling.

0

精彩评论

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