mvc音乐商店中的paypal iPN问题
我试图将购物车中的商品传递给 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您在渲染此视图的控制器操作中传递模型,并且此模型的
CartItems
属性不为空:我不知道您所说的模型不是什么意思上一页为 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: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.