2017-01-19 96 views
2

当调用CheckoutController的数据动作,我不断收到以下错误无效项:参数字典包含参数的OrderID

enter link description here 我使用这种技术在其他几个控制器和I避风港传递参数那里没有任何麻烦。下面显示了我的CheckoutController的代码和默认路由。提前致谢!

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using WebApplication2.Functions; 
using WebApplication2.Models; 

namespace WebApplication2.Controllers 
{ 
    public class CheckoutController : Controller 
    { 
     private thelearningbayEntities _db = new thelearningbayEntities(); 
     private Auth Permission = new Auth(); 

     [HttpGet] 
     public ActionResult Data(int Orderid) 
     { 
      if (Permission.Check(0)) 
      { 
       var email = Session["email"].ToString(); 
       _db.Configuration.ProxyCreationEnabled = false; 

       var result = (from order_line in _db.order_line 
           join orders in _db.orders on order_line.id_order equals orders.id_order 
           join product in _db.product on order_line.p_id equals product.p_id 
           where (orders.email == email) && (orders.id_order == Orderid) 

           select new { order_line.amount, product.p_name, product.price, product.t_image}).ToList(); 

       return Json(result, JsonRequestBehavior.AllowGet); 
      } 
      Session["referrer"] = "/Checkout/"; 
      return RedirectToAction("Index", "Login"); 

     } 
    } 
} 

Routeconfig:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using System.Web.Routing; 

namespace WebApplication2 
{ 
    public class RouteConfig 
    { 
     public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

      routes.MapRoute(
       name: "Product", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "MainPage", action = "Index", id = UrlParameter.Optional } 
      ); 
     } 
    } 
} 

回答

6

动作方法的参数更改为Id让你请求的URL的默认路由模式,这是{controller}/{action}/{id}匹配。

public ActionResult Data(int id) 
{ 
     //use id 
} 

或者

修复其生成连结此操作方法明确地使用orderId routeValue(查询字符串键)的代码。

例如,如果正在使用的Html.ActionLink方法,

@Html.ActionLink("Checkout","Data","Checkout",new { orderId=20 },null) 

或者标记(辅助最终产生如下面的标记)

<a href="/Checkout/Data?orderId=20">Checkout</a> 
相关问题