MVC跨控制器传值问题,请各位帮忙。
我有两个控制器:Address和Order,我在Address中的view页面添加表单信息(其中包含有订单信息),提交表单的时候我要传递一个OrderId到控制器Order中的方法Details中,我想以URL的信息传递过去。Address表单提交的[httppost]ActionResult的代码:
public ActionResult Index(Order order, FormCollection formcollection) {return RedirectToAction("Details", "Order", new { id = order.OrderId }); $("#button_submit").click(function () { $("form[0]").submit(); }); public ActionResult Details(string orderid) { Order order = datacontext.GetOrder(orderid); return View(order); }public ActionResult Index(Order order, FormCollection formcollection) {return RedirectToAction("Details", "Order", new { orderid = order.OrderId });public ActionResult Details(string orderid) { Order order = datacontext.GetOrder(orderid); return View(order); }
[解决办法]
public ActionResult Index(Order order, FormCollection formcollection) {return RedirectToAction("Details", "Order", new { [color=#FF0000]orderid[/color] = order.OrderId });public ActionResult Details(string [color=#FF0000]orderid[/color]) { Order order = datacontext.GetOrder(orderid); return View(order); }
[解决办法]
http://localhost:5611/Order/Details/1111230941401054,用的是你的 url路由,你的路由配置参数是什么,就用什么来接收,你的路由 默认参数是id的话 就用 id
public ActionResult Details(string id)
你也可以 自己组装 return Redirect("/Order/Details?id=1111230941401054");
[解决办法]
new { id = order.OrderId });
=>
new { orderid = order.OrderId });