mvc音乐商店中的paypal iPN问题

发布于 2024-10-06 07:33:18 字数 1349 浏览 0 评论 0原文

我试图将购物车中的商品传递给 PayPal,但收到以下错误:

对象引用未设置为对象的实例。

我的代码是:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> 地址及付款方式

<h1>Checkout with PayPal</h1>

<form id="PayPal" name="PayPal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" />

<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="[email protected]" />

<% foreach (var item in Model.CartItems)
   { %>
<%=Html.Hidden("item_name" + item.Count.ToString(), item.Design.Title)%>
<%=Html.Hidden("amount" + item.Count.ToString(), item.Design.Price)%>
<%=Html.Hidden("quantity" + item.Count.ToString(), item.Count.ToString())%>
<%=Html.Hidden("shipping" + item.Count.ToString(), 0)%>
<%=Html.Hidden("handling" + item.Count.ToString(), 0)%>
<% } %>
<input type="image" src="https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image" align="left" />

该错误突出显示 Model.CartItems 中的 foreach 项目 - 但是在上一页上该项目不为空。似乎该项目将显示为空。

I am trying to pass my items in the cart to paypal and am receiving the following error:

Object reference not set to an instance of an object.

My code is:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

Address and Payment

<h1>Checkout with PayPal</h1>

<form id="PayPal" name="PayPal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" />

<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="[email protected]" />

<% foreach (var item in Model.CartItems)
   { %>
<%=Html.Hidden("item_name" + item.Count.ToString(), item.Design.Title)%>
<%=Html.Hidden("amount" + item.Count.ToString(), item.Design.Price)%>
<%=Html.Hidden("quantity" + item.Count.ToString(), item.Count.ToString())%>
<%=Html.Hidden("shipping" + item.Count.ToString(), 0)%>
<%=Html.Hidden("handling" + item.Count.ToString(), 0)%>
<% } %>
<input type="image" src="https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image" align="left" />

The error is highlighting the foreach item in Model.CartItems - however on the previous page this item is not null. Seems that item is coming up as null.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦旅人picnic 2024-10-13 07:33:18

确保您在渲染此视图的控制器操作中传递模型,并且此模型的 CartItems 属性不为空:

public ActionResult Foo()
{
    ShoppingCartViewModel model = FetchYourModelFromSomewhere();
    // at this stage model and model.CartItems should not be null
    return View(model);
}

我不知道您所说的模型不是什么意思上一页为 null,但控制器操作应始终将模型传递给视图。

Make sure that you are passing the model in the controller action rendering this view and that the CartItems property of this model is not null:

public ActionResult Foo()
{
    ShoppingCartViewModel model = FetchYourModelFromSomewhere();
    // at this stage model and model.CartItems should not be null
    return View(model);
}

I don't know what do you mean when saying that the model is not null on the previous page but the controller action should always pass a model to the view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文