【问题标题】:The parameters dictionary contains a null entry for parameter Orderid参数字典包含参数 Orderid 的空条目
【发布时间】:2017-01-19 20:56:41
【问题描述】:

在调用 CheckoutController 的 Data 操作时,我不断收到以下错误:

我正在使用这种技术在其他几个控制器中传递参数,我在那里没有遇到任何问题。我的 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");

        }
    }
}

路由配置:

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 }
            );
        }
    }
}  

【问题讨论】:

    标签: c# asp.net-mvc


    【解决方案1】:

    将您的操作方法参数更改为Id,以便您的请求网址匹配默认路由模式,即{controller}/{action}/{id}

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

    或者

    修复生成此操作方法链接的代码,以显式使用orderId routeValue(querystring key)。

    例如,如果你使用Html.ActionLink方法,

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

    或标记(帮助程序最终生成如下标记)

    <a href="/Checkout/Data?orderId=20">Checkout</a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-12
      • 2018-01-21
      • 1970-01-01
      • 2017-05-12
      • 2013-12-15
      • 1970-01-01
      相关资源
      最近更新 更多