Friday, 24 August 2012

Using ViewBag for MVC entity model:

In this after adding entity DB table to the project it generated some methods as well with our table name like for example my table name is "tblcontact"  it takes model name as my "tblcontact"  name... then i'm taking data into an object, that make to add my data  to thattable automatically as by doing as follows:
        [HttpPost] 
          public ActionResult Index(tblcontact Contact)
        {
            techdbEntities1 obj = new techdbEntities1();
            obj.AddTotblcontacts(Contact);
            obj.SaveChanges();
            ViewBag.contact = Contact;

            return View();

        }

    Then same we can return this to our view... for access... and rendering... to show the values... @ViewBag.contact.name  by the way we can render values in view.
       

No comments:

Post a Comment