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.