There are several ways to reach the home / detail page, such as this, there really is no better way to do this. AJAX may be the most elegant and user friendly, but this is by no means the โrightโ answer.
By looking at the code you posted, the simplest thing you could do is to have one action method and one look.
public class OrdersViewModel { public IEnumerable<Order> Orders { get; set; } public OrderItems SelectedOrderItems { get; set; } } public ActionResult Orders(Guid id, Guid? orderId) { var model = new OrdersViewModel(); model.Orders = Services.GetOrders(id); if (orderId != null) { model.SelectedOrderItems = Services.GetOrderLines(orderId); } return View(model); }
The disadvantage of this rather basic approach is that you will probably have 2 Guides polluting your Url, and this example does not check if orderId really belongs to the identifier (user?) - regardless of what the first Guid represents. You can handle this with a few lines of code.
A more elegant way to handle this, if you don't mind changing your Url, is to stick with the second method of action. I hope you can determine the "owner" of the order part from the part itself or somehow it will not require you to pass this into the action method. This helps to ensure that your view shows only data from the right wizard.
public ActionResult OrderDetails(Guid id ) { var orderLines = Services.GetOrderLines(id); var model = new OrdersViewModel();
Your opinion stated in your question can remain largely unchanged. Display action links that represent all orders. Then visualize the order details, if they are in the model:
@if (Model.SelectedOrderItems!= null) { }
If you process order details on other pages, you want to place order details in a partial view so as not to duplicate any markup. If it appears only here, then there really is no reason why you could not have your markup in this view.
source share