Introduction:
In this article, i am going explain about how to create a asp.net mvc web application using asp.net.
Main:
For creating asp.net mvc web application please goto file –> new –> project and select asp.net
mvc2 template,

After clicking on OK, Visual Studio will ask you if you want to create a test project. This dialog
offers the choice between several unit testing frameworks that can be used for testing your ASP.NET
MVC application.

You can decide for yourself if you want to create a unit testing project right now—you can also add
a testing project later on. Letting the ASP.NET MVC project template create a test project now is
convenient because it creates all of the project references, and contains an example unit test, although
this is not required. For this example, continue by adding the default unit test project.

After the ASP.NET MVC project has been created, you will notice a default folder structure. There’s a
Controllers folder, a Models folder, a Views folder, as well as a Content folder and a Scripts folder.
ASP.NET MVC comes with the convention that these folders (and namespaces) are used for locating the
different blocks used for building the ASP.NET MVC framework. The Controllers folder obviously contains
all of the controller classes; the Models folder contains the model classes; while the Views folder contains
the view pages. Content will typically contain web site content such as images and stylesheet files, and
Scripts will contain all of the JavaScript files used by the web application. By default, the Scripts folder
contains some JavaScript files required for the use of Microsoft AJAX or jQuery.
see this below demonstration,
Allready we discussed view is just used html resources,so just add a new webpage under view and named it
welcome.aspx,
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WelCome.aspx.cs" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Content ID="Content1"
ContentPlaceHolderID="MainContent"
runat="server">
<h1><%=ViewData["Welcomestring"]%></h1>
</asp:Content>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WelCome.aspx.cs" Inherits="System.Web.Mvc.ViewPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> <h1><%=ViewData["Welcomestring"]%></h1> </asp:Content> </div> </form> </body> </html> |
here we are just trying to display welcome string using viewstate,
We allready discussed all business logic’s are coming under model,here we are returning a simple welcome string,so
i just added the properties for that welcomestring,

<
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace mvcdemo.Models
{
public class WelcomeString : Controller
{
//
// GET: /WelcomeString/
public class welcomestr
{
//return View("Welcome to MVC,its really very easy and cool");
public string Getstring { get; set; }
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace mvcdemo.Models { public class WelcomeString : Controller { // // GET: /WelcomeString/ public class welcomestr { //return View("Welcome to MVC,its really very easy and cool"); public string Getstring { get; set; } } } } |
next we need to create a controller for working with the html page,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mvcdemo.Models;
namespace mvcdemo.Controllers
{
public class WelcomeController : Controller
{
//
// GET: /Welcome/
public ActionResult Index()
{
WelcomeString.welcomestr objwel = new WelcomeString.welcomestr();
objwel.Getstring = "Welcome to MVC,its really very easy and cool";
ViewData["Welcomestring"] = objwel.Getstring;
return View();
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using mvcdemo.Models; namespace mvcdemo.Controllers { public class WelcomeController : Controller { // // GET: /Welcome/ public ActionResult Index() { WelcomeString.welcomestr objwel = new WelcomeString.welcomestr(); objwel.Getstring = "Welcome to MVC,its really very easy and cool"; ViewData["Welcomestring"] = objwel.Getstring; return View(); } } } |
thatsit!
Conclusion:
Hope this simple program helps you to understand about MVC,
Happy coding.
Usually I do not post on blogs, but I would like to say that this article really forced me to do so! Thanks, really nice article.
Yeah! Excellent writing, keep up the tremendous work. This is the sort of info that ought to obtain acknowledgement pertaining to it’s craft. Far more authors ought to learn from you. This is actually right on the money.
I like your website. Very practical and very motivational. Thanks a bunch. This will help me a lot.
Just came upon your article and will check out additional ones. Looks like real good stuff.
That’s right! Excellent piece, keep in place the amazing job. This is the sort of info that ought to get acknowledgement pertaining to it’s workmanship. Far more internet writers should learn from you. This is actually right on the money.
I like your layout, the actual fact that your website is a tad bit different makes it so useful, I get tired of discovering the same stuff almost all of the time. I’ve I merely stumbled on this page by you Cheers.
Interesting write-up. Had been did you got all the information from…
Who needs newspapers when they have such a nice blog to read. I was really wondering on this subject so I went to Bing, typed my question and voila, here I landed. Such a pleasant surprise to get to your blog. Thank you for your time and for this wonderful post. Thank you smarte search engine for bringing me here.
If you are open to having a guest blog poster please reply and let me know. I will provide you with unique content for your blog, thanks.
I was suggested this website by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are wonderful! Thanks!