我的订单应用程序是一个单页应用程序,它使用自定义指令搜索对话框,并在处理订单时保留在 / ManageOrders / Index 页面URL上。
但是,用户可以通过邮件中的订单链接获取订单的电子邮件通知。该链接包括ID参数,该参数是订单ID的可选路由参数。这一切都很有效,除了当用户正在处理电子邮件订单时,URL将类似于 ManageOrders / Index / 33 。然后,每个后续搜索都会找到新订单,但仍会在网址栏中显示 / 33 。这看起来很糟糕,并且在刷新时也返回到订单33(对用户来说不明显)。
这只是在SPA中混合被调用页面的垮台,还是有一种技术可以删除URL中的 / ID ?
[HttpGet]
[Route ("ManageOrders/Index/{id?}")]
public ActionResult Index(int id = 0)
{
// this Index action is from inside the SPA, as normal
if (id == 0)
{
TempData["StartInTab"] = JsonConvert.SerializeObject("OrderInfo");
return View("~/Areas/OM/Views/ManageOrders/ManageOrders.cshtml",
TempData["Selected_Order_Data"]);
}
else
// this Index action has an ID being passed in from an external link,
//so needs to fetch the data first and start with Follow Ups
{
TempData["StartInTab"] = JsonConvert.SerializeObject("FollowUpTasks")
var db = new OrdersEntities();
var selectedOrder = db.ORDERS.Where(x => x.ORDER_ID == id)…
TempData["Selected_Order_Data"] = JsonConvert.SerializeObject(selectedOrder);
return View("~/Areas/OM/Views/ManageOrders/ManageOrders.cshtml",
TempData["Selected_Order_Data"]);
// RouteData.Values.Remove("id"); // this alternative doesn’t work – it strips the
// return RedirectToAction("Index"); // action “/Index” in the URL, which is needed
}
}
另外,我尝试使用RedirectToAction,但由于某种原因,当删除(“id”)时会从URL中删除/ Index,这会导致其他问题。
感谢您采用任何更好的方法。