Hello i'm newbie to MVC, i want to display webgrid in view,I'm trying to display create and display in same page,i'm getting problem at the time of displaying data in webgrid,

This is my code: Controller:

[HttpPost]
    public ActionResult Insert(Torder Model)
    {
        if(ModelState.IsValid)
        {
            try
            {
                ntity.Torders.Add(Model);
                ntity.SaveChanges();
                ModelState.Clear();
                TempData["notice"] = "Successfully registered";
            }
            catch(Exception ex)
            {
                TempData["Failure"] = ex;
            }
        }
        else
        {
            TempData["Failure"] = "Record Not Saved";
        }

        //var empoyees = Employee.GetList();

        IEnumerable<Torder> model1 = GetProducts();
        return View(model1);
    }
    public IEnumerable<Torder> GetProducts()
    {
        List<Torder> objStudent = new List<Torder>();
        ///*Create instance of entity model*/

        /*Getting data from database for user validation*/
        var _objuserdetail = (from data in ntity.Torders
                              select data);
        foreach (var item in _objuserdetail)
        {
            objStudent.Add(new Torder { Cid = item.Cid, Ccustomername = item.Ccustomername, Citem = item.Citem, Corderamount = (int)item.Corderamount});
        }
        return objStudent;
    }

Related posts

Recent Viewed