Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi sir,

i am new to mvc 4,actually my problem i am retrieving quantity from one table it's come 1 by default from table1 and i am inserting table1 quantity in bascket table2 and based on column id i am trying to update bascket table2 quantity ,it is not responding ..i am giving my code below ..please help me to update quantity

(Actually my problem is Basket table quantity comes 1 from table1,i am trying to insert my default quantity in bascket table...in controller page in update action link id is processing but default quantity(what i am giving) is not processing the test object...suppose i am giving default object it is updating...please help me to solve this problem )
This is my .cs page
C#
public class tbl_Bascket
   {
       [Key]
       public int OrderID { get; set; }
       public int ItemCode { get; set; }
       public string username { get; set; }
       public int Quanitity { get; set; }
       public decimal Price { get; set; }
       public decimal TotalPrice { get; set; }
       public DateTime OrderDate { get; set; }
       public string ProductName { get; set; }
   }
   public class tbl_BascketContext:DbContext
   {
       public DbSet<tbl_bascket> basket { get; set; }
   }

This is my Controller page
C#
private tbl_BascketContext dbbasket = new tbl_BascketContext();

public ActionResult update(int id)
{
    tbl_Bascket test = dbbasket.basket.Find(id);
    int qty = test.Quanitity;
    SqlCommand cmd = new SqlCommand("update tbl_Bascket set Quanitity='" + qty + "'          where OrderID='" + id + "'", con); 
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
    return RedirectToAction("Bascket");
}

This is my html page
C#
@using (Html.BeginForm())
{
    @foreach (var item in Model)
        {
          @Html.TextBoxFor(m => item.Quanitity)
          @Html.ActionLink("update", "update", new { id = item.OrderID })
        }
}


Thanks for advance
Gowtham k
Posted
Updated 8-Oct-14 1:06am
v6
Comments
Xavi Giqwa 23-Sep-14 6:02am    
I suggest that you use Entity Framework with MVC to make things easy for you.
check this link: http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900