2017-01-19 8 views
2

CheckoutControllerのデータアクションを呼び出すときに、私は次のエラーを取得しておくためのヌルエントリが含まれていますそこには何のトラブルもなかった。 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:あなたの要求のURLが{controller}/{action}/{id}あるデフォルトのルーティングパターンを、一致するように

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にあなたのアクションメソッドのパラメータを変更し

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> 
(ヘルパーは、最終的には以下のようなマークアップを生成します)
関連する問題