In this article, I will look to create a simple customerInformation model using ASP.NET MVC3.
Here is I have two Views, one (Index.cshtml) is for enter data in
CustomerInformation Model and second (ShowData.cshtml) is for show the
CustomerInformation Model data.
Steps for creating a new Application in ASP.NET MVC4
1. Open studio 2010 and create a new ASP.NET MVC 4 Web Application (Razor) project as seen below:
Select the Empty Template and then select the Razor in View Engine Drop Down ListBox Then Press Ok:
Add a controller in your project and give name as HomeController as shown in the below figure:
4. Add a Model Class in your project and give name as CustomerInformation as
shown in the below figure:
5. Add two Views in the project first view with the Name Index it’s create with
Strongly type and second view with the name ShowData and it’s also create
Strogly type.
Index.cshtml
@model CustomerInformationMVC3.Models.CustomerInformation
@{
ViewBag.Title = "Index";
}
@*<script type="text/javascript">
function s() {
location.href = "/Home/ShowData"
}
</script>*@
@using (Html.BeginForm("ShowData", "Home"))
{
@Html.Label("Customer Name:: ");
@Html.TextBoxFor(m => m.customer_Name)<br />
@Html.Label("Customer Age:: ");
@Html.TextBoxFor(m => m.customer_Age)<br />
@Html.Label("Customer Contact:: ");
@Html.TextBoxFor(m => m.customer_Contact)<br />
@Html.Label("Customer Address:: ");
@Html.TextBoxFor(m => m.customer_Address)<br />
<input type="submit" value="Submit" />
}
ShowData.cshtml
@model CustomerInformationMVC3.Models.CustomerInformation
@{
ViewBag.Title = "ShowData";
}
<h2>ShowData</h2>
Customer Name  @Model.customer_Name <br />
Customer Age  @Model.customer_Age <br />
Customer Contact  @Model.customer_Contact <br />
Customer Address  @Model.customer_Address <br />
HomeController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CustomerInformationMVC3.Models;
namespace CustomerInformationMVC3.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public ActionResult ShowData(CustomerInformation _customerInformation)
{
return View(_customerInformation);
}
}
}
Model Class CustomerInformation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CustomerInformationMVC3.Models
{
public class CustomerInformation
{
public string customer_Name{ get; set; }
public string customer_Address{ get; set; }
public int customer_Age{ get; set; }
public string customer_Contact{ get; set; }
}
}
Run this application, you will see the following screen:
You can enter the customer Name, Age, Contact, Address and press Submit
After press Submit Button , you will see the following screen:
Leave Comment