C# 参数字典包含参数Orderid的空条目
调用CheckoutController的数据操作时,我不断收到以下错误: 我使用这种技术在其他几个控制器中传递参数,在那里我没有遇到任何问题。签出控制器和默认路由的代码如下所示。提前谢谢C# 参数字典包含参数Orderid的空条目,c#,asp.net-mvc,C#,Asp.net Mvc,调用CheckoutController的数据操作时,我不断收到以下错误: 我使用这种技术在其他几个控制器中传递参数,在那里我没有遇到任何问题。签出控制器和默认路由的代码如下所示。提前谢谢 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using WebApplication2.Functions; using WebAppli
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");
}
}
}
路线图:
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 }
);
}
}
}
将操作方法参数更改为
Id
,以便请求url与默认路由模式匹配,即{controller}/{action}/{Id}
public ActionResult Data(int id)
{
//use id
}
或
修复生成指向此操作方法的链接的代码,以显式使用orderId
routeValue(querystring键)
例如,如果您正在使用Html.ActionLink
方法
@Html.ActionLink("Checkout","Data","Checkout",new { orderId=20 },null)
或标记(帮助器最终生成如下所示的标记)
<a href="/Checkout/Data?orderId=20">Checkout</a>