Introduction
MVC is one of three ASP.NET programming models.
MVC is a framework for building web applications using an MVC (Model View Controller) design:
- The Model represents the application core (for instance a list of database records).
- The View displays the data (the database records).
- The Controller handles the input (to the database records).
The MVC model also provides full control
over HTML, CSS, and JavaScript.
Prerequisites
- Install Visual Studio 2010 (SP1)
- Install ASP.NET MVC4
- Install Microsoft SQL Server Compact 4.0
- Install Opera Mobile Emulator
Getting Started
The following steps will show how to build
a MVC4 Mobile application.
Step 1
Open Visual Studio, select New Project -> ASP.NET MVC4 Web Application.
![Image 1](/KB/mobile/438585/image001.jpg)
Step 2
Select Mobile Application from the Project
Template.
![Image 2](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
Step 3
Go to Solution Explorer, right-click on the App_Data folder, and click on Add New Item.
![Image 3](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
Select SQL
Server Compact 4.0 Local Database and name it as Movies.sdf.
Step 4
Database is
added to the App_Data folder.
![Image 4](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
Step 5
Create a
table and name it MovieDBs.
![Image 5](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
Step 6
Add
ConnectionString in Web.config.
![Image 6](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
Step 7
Right-click
on Model->Add->Class and paste the following code:
![Image 7](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
Note: ConnectionString name and Class name should be the same.
Step 8
Right-click on Controller->Add->Controller Add Controller Window Popup.
![Image 8](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
Click on Add button and it will create a Movies Controller.
Step 9
Run application using Opera Mobile Emulator and it shows the following result.
![Image 9](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)