Asp .net Mvc is the Web Development framework from Microsoft based on
the MVC architecture.
Asp .Net MVC is getting installed as a part of Visual Studio 2010 and
Visual Web Developer 2010.
Asp .Net 2 MVC Empty Web Application Project
Asp .Net MVC 2 Web Application comes with predefined
Membership and other frills which makes it easy
to get a head start, but abstracts away the inner working of MVC.
But I am taking another route. There is another
Asp .Net MVC 2 Empty Web Application Project.
Lets start with Controllers. Controllers are responsible for handling
incoming request. It's a class that inherits from System.Web.Mvc.Controller.
I am naming the controller HomeController.
I am replacing the existing code of HomeController which expects a View (which will be explained late) with a function that returns a string.
If you run the application you will see a web page with the value of function.
Views
Now Let's turn our attention to Views. A view is typically what you see in an Asp .Net MVC Application.
Preferably start a new new Asp .Net MVC 2 Empty Web Application so that we can start afresh.
The following diagram shows the default code within the HomeController class.
If you run the application you will receive a detailed error message stating that the view is missing.
So right click the Index method and select Add View.
Make sure you check off the Select MasterPage option because we haven't introduced Master Pages.
A view template called Index.aspx will created for you under ~/Views/Home/ directory.
Which comprises of plain HTML.
Now if you run the application you will receive a blank form.
Lets replace the existing code with the code below. The code will return a
ViewData structure
public ViewResult Index()
{
ViewData["Blog"] = "ShalvinPD.blogspot.com";
return View();
}
Now lets show the ViewData in the View.
Asp .Net MVC Views
Easiest way to develop Asp .Net MVC views are by using Html Helpers.
Name <%: Html.TextBox("Name") %>
<br />
<%: Html.CheckBox(".Net", true) %>.Net
<br />
<%: Html.RadioButton("Male", true) %>Male
<br />
<%: Html.RadioButton("Female", false) %>Female
<div>
Password <%: Html.Password("myPassword")%>
</div>
<div>
Address <%: Html.TextArea("Address", "Shalvin P D", 5, 20, null)%>
</div>
Kmug<%: Html.DropDownList("Kmug", new SelectList(new[] { "Shalvin", "Mathew" }), "Shalvin") %>
<br />
Technologies<%: Html.ListBox("myList", new SelectList(new[] { "Asp .Net", "Asp .Net Mvc" }), "Shalvin") %>
Friday, April 30, 2010
Asp .Net MVC 2 with Visual Studio 2010 or Visual Web Developer 2010
Labels:
Asp .Net Mvc,
Asp .Net MVC 2,
MVC,
Shalvin
Subscribe to:
Post Comments (Atom)
SharePoint Development tools can facilitate the organization with the following features:
ReplyDeleteWebsite Management
Content Management
Community Management
Insights
Composites
Search