我有两个控制器:Address和Order,我在Address中的view页面添加表单信息(其中包含有订单信息),提交表单的时候我要传递一个OrderId到控制器Order中的方法Details中,我想以URL的信息传递过去。Address表单提交的[httppost]ActionResult的代码:
- C# code
public ActionResult Index(Order order, FormCollection formcollection) {return RedirectToAction("Details", "Order", new { id = order.OrderId });
- JScript code
$("#button_submit").click(function () { $("form[0]").submit(); });
- C# code
public ActionResult Details(string orderid) { Order order = datacontext.GetOrder(orderid); return View(order); }
------解决方案--------------------------------------------------------
global里面设置routes了没?
------解决方案--------------------------------------------------------
用 Redirect
------解决方案--------------------------------------------------------
- C# code
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); }
------解决方案--------------------------------------------------------
- C# code
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 });