Your Models
public class Employee
{
public int ID { get; set; }
public String Name { get; set; }
public BillingAddress billingAddress { get; set; }
}
public class BillingAddress
{
public int ID { get; set; }
public int HouseNo { get; set; }
public String Street { get; set; }
public String Locality { get; set; }
public String City { get; set; }
public String District { get; set; }
public String State { get; set; }
public String Country { get; set; }
public int PinCode { get; set; }
}
And View
@model FormAuth.Models.Employee
@{
ViewBag.Title = "Add";
}
Add
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
Employee
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
BillingAddress
@Html.LabelFor(model => model.billingAddress.HouseNo)
@Html.EditorFor(model => model.billingAddress.HouseNo)
@Html.ValidationMessageFor(model => model.billingAddress.HouseNo)
@Html.LabelFor(model => model.billingAddress.Street)
@Html.EditorFor(model => model.billingAddress.Street)
@Html.ValidationMessageFor(model => model.billingAddress.Street)
@Html.LabelFor(model => model.billingAddress.Locality)
@Html.EditorFor(model => model.billingAddress.Locality)
@Html.ValidationMessageFor(model => model.billingAddress.Locality)
@Html.LabelFor(model => model.billingAddress.City)
@Html.EditorFor(model => model.billingAddress.City)
@Html.ValidationMessageFor(model => model.billingAddress.City)
@Html.LabelFor(model => model.billingAddress.District)
@Html.EditorFor(model => model.billingAddress.District)
@Html.ValidationMessageFor(model => model.billingAddress.District)
@Html.LabelFor(model => model.billingAddress.State)
@Html.EditorFor(model => model.billingAddress.State)
@Html.ValidationMessageFor(model => model.billingAddress.State)
@Html.LabelFor(model => model.billingAddress.Country)
@Html.EditorFor(model => model.billingAddress.Country)
@Html.ValidationMessageFor(model => model.billingAddress.Country)
@Html.LabelFor(model => model.billingAddress.PinCode)
@Html.EditorFor(model => model.billingAddress.PinCode)
@Html.ValidationMessageFor(model => model.billingAddress.PinCode)
}
@Html.ActionLink("Back to List", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
you can write your view in HTML syntax only, instead of razor syntax. But take care of name of the controls (As Laxmi Said).
public class EmployeeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Add()
{
return View();
}
[HttpPost]
public ActionResult Add(FormAuth.Models.Employee employee)
{
return View();
}
}