Creating an MVC + ASP.net + SQL Site in 10 minutes
- Get the proper software (___)
- File > New Project > Web > Asp.net MVC 2 Web App
- Call the solution “MVCPlayground“
- The solution name (eg-MVCPlayground) will be the namespace for your solution.
- In solution explorer, right click App Data > Add > New Item > Data > Sql Server database > IdeaDB
- In server explorer, expand IdeaDB (click on the +), right click Tables, add new table
- If solution explorer is not visible, View>Server Explorer.
- Call it IdeaTable
- You could call it Idea, but the term becomes overloaded…we may change this.
- In solution explorer, right click Models > Add > New Item
- Select ADO.net Entity Data Model
- Name the file DataModel.edmx
- Generate from DB, select IdeaDB.mdf, the the check checked.
- Name the thing (bottom box) IdeaDBEntities
- Select (check box) tables and keep checkboxes checked
- Model Namespace should be Model
- Rename the entity from IdeaTable to Idea
- Delete Controllers > Home Controller
- Delete Views > Home > Index and About
- Delete Test > Controllers > Home
- Right Click controllers > Add > Controllers and name it HomeControllers, keep the checks checked
- In HomeController.cs under “public class…” add ”private IdeaDBEntities _entities = new IdeaDBEntities();” and hit CTRL+. on IdeaDBEntities to add the using reference.
- Build Solution (this makes the classes available for follow on steps)
- For Index
- Make it ”return View(_entities.Ideas);”
- Right click index, check create strongly typed view
- Select MVCPlayground.models.idea (this is solutionName.ModelNamespace)
- For View Content, select List
- Duplicate the above steps for create, but select “create” from drop down and do not update the “return View();”
- On the create view…
Advertisement
