日期:2014-05-17  浏览次数:20413 次

MVC跨控制器传值问题,请各位帮忙。
我有两个控制器: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();
            });
,#button_submit这个是图片按钮的ID,这样提交的形式是http://localhost:5611/Order/Details/1111230941401054,并不是URL的形式http://localhost:5611/Order/Details?id=1111230941401054,这样提交过去之后,Order控制器中的Details中的id没有得到值,Details的代码:
C# code
 public ActionResult Details(string orderid)
        {
            Order order = datacontext.GetOrder(orderid);
            return View(order);
        }
。现在的问题是为什么Order中的id没有值呢,如果我想用URL的方式传递ID的值,要怎么传递。多谢各位耐心的看,不知道我描述的够清楚吗

------解决方案--------------------
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 });