In below MVC Shopping cart code i am getting error please help me to fix it....

Last Reply 4 days ago By dharmendr

Posted 4 days ago

i am getting this type of error in my shopping cart view.....

@using MPIS_MVC1.Models;

<h2>
    cart
</h2>
<table>
    <tr>
        <th>Plant Name</th>
        <th>Price</th>
        <th>Quantity</th>
        <th>Total</th>
    </tr>


    @foreach (var cart in (List<cart>)Session["cart"])
    {

        string q1 = @Model.quantity;
        int q2 = @Convert.ToInt32(q1.ToString());


    <tr>
        <td>@cart.medipadd.plantname</td>
        <td>@cart.medipadd.price</td>
        <td>@cart.medipadd.quantity</td>
        <td>@(String.Format("{0:N0}", cart.medipadd.price * q2))</td>
    </tr>
}
</table>



// contoller code is given below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.SqlClient;
using MPIS_MVC1.Models;
using System.Net;

namespace MPIS_MVC1.Controllers
{
    public class AddcartController : Controller
    {
        // GET: Addcart
        MPISEntities1 m1 = new MPISEntities1();
        private String srtcart = "cart";
        public ActionResult Addtocart()
        {
            return View();
        }



        public ActionResult Ordernow(int? id)
        {

            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            if (Session[srtcart] ==null)
            {
                List<cart> Iscart = new List<cart>
                {
                    new cart(m1.medipadds.Find(id),"1")
                };

            Session[srtcart] = Iscart;

            }
            else
            {
                List<cart> Iscart = (List<cart>)Session[srtcart];
                Iscart.Add(new cart(m1.medipadds.Find(id), "1"));
                Session[srtcart] = Iscart;
            }
            return View("Addtocart");
        }
    }
   
    

}

this is my view and controller code...i am getting an error in my code...so please fix it....

You are viewing reply posted by: dharmendr 4 days ago.