Click here to Skip to main content
13,139,569 members (50,855 online)
Rate this:
Please Sign up or sign in to vote.
See more:
how we can insert data in database using mvc3?
Posted 17-Jul-12 3:24am
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


follow this
Member 10831242 28-May-14 3:58am
i have created contextclass and inseting record and retrieving also..but i dont konw where that record stores...where is the DB now ??? how can i check
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Step 1 : Add ADO.NET entity data model for your table, it will be added in model folder
Step 2 : Create a class for the table in which you are going to insert data in model folder
public class movie
        public string title { get; set; }
        public DateTime releasedate { get; set; }
        public string genre { get; set; }
        public decimal price { get; set; }

Step 3 : Create a controller in which you are going to put code for insert method
Step 4 : Create two actions in controller file, one for HttpGet and HttpPost
        public ActionResult addmovie()
            return View();
        public ActionResult addmovie(movie mv)
            Movie newmv = new Movie();
            newmv.Title = mv.title;
            newmv.ReleaseDate = mv.releasedate;
            newmv.Genre = mv.genre;
            newmv.Price = Convert.ToDecimal(mv.price);
            return View();

Step 5 : Create the view for actions we just created
    ViewBag.Title = "addmovie";
@using (Html.BeginForm())
        <label>Title : </label>
        <label>Release DAte : </label>
        <label>Genre : </label>
        <label>Price : </label>
        <input id="Submit1" type="submit" value="Add Movie" />
9410662422 1-Apr-13 7:14am
Where you have created your DataContext object ? I am asking because i have created the object of DataContext classes in my Model class. And if i talk about your code you have written "db.SaveChanges()" in your controller class. Please explain how you have accessed DataContext class object from model in controller OR Have you created the object in your controller ?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100