View Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Web.Mvc;
namespace MvcApplication2.Models
{
public class EMPVM
{
[Required(ErrorMessage = "Eid should not be blank.")]
public int? EID { get; set; }
[Required(ErrorMessage = "Name should not be blank.")]
public string NAME { get; set; }
[Required(ErrorMessage = "Password should not be blank.")]
[StringLength(8,MinimumLength=6,ErrorMessage="Password length between 6 to 8 charecters.")]
[DataType(DataType.Password)]
public string PASSWORD { get; set; }
[DisplayName("CONFIRM PASSWORD")]
[System.ComponentModel.DataAnnotations.Compare("PASSWORD",ErrorMessage="Confirm password must be same with passwrod.")]
[Required(ErrorMessage = "Confirm password should not be blank.")]
[DataType(DataType.Password)]
public string CP { get; set; }
[Required(ErrorMessage="Address should not be blank.")]
[DataType(DataType.MultilineText)]
public string ADDRESS { get; set; }
[Required(ErrorMessage = "Salary should not be blank.")]
[Range(5000,500000,ErrorMessage="Salary range between 5000 to 500000.")]
public decimal? SALARY { get; set; }
[Required(ErrorMessage = "Dob should not be blank.")]
[Remote("Check","Home",ErrorMessage="Dob should not greater than or equal to current date.")]
public DateTime? DOB { get; set; }
[Required(ErrorMessage = "Email should not be blank.")]
[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*",ErrorMessage="Invalid email Id.")]
public string EMAIL { get; set; }
[Required(ErrorMessage = "Gender should not be blank.")]
public string GENDER { get; set; }
[Hvalidate(ErrorMessage = "Please select a hobby.")]
[DisplayName("HOBBY")]
public List<MetaData> LHOBBY { get; set; }
[Ivalidate(ErrorMessage = "Please select a interest.")]
public List<string> INTEREST { get; set; }
public List<MetaData> LINTEREST{ get; set;}
[Required(ErrorMessage = "Please select a country.")]
public int COUNTRY { get; set; }
public List<MetaData> LCOUNTRY { get; set; }
[Required(ErrorMessage = "Please select a state.")]
public int STATE { get; set; }
public List<MetaData> LSTATE { get; set; }
public EMPVM()
{
LHOBBY = new List<MetaData>();
LINTEREST = new List<MetaData>();
LCOUNTRY = new List<MetaData>();
LSTATE = new List<MetaData>();
}
}
public class Hvalidate : ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null)
return false;
return ((List<MetaData>)value).Count(m=>m.Selected==true)>0;
}
}
public class Ivalidate:ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null)
return false;
return !(((List<string>)value).ToList().Count() == 0);
}
}
public class MetaData
{
public int ID { get; set; }
public string NAME { get; set; }
public bool Selected { get; set; }
}
public class MetaData1
{
public string NAME { get; set; }
}
}
Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication2.Models;
namespace MvcApplication2.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
[HttpGet]
public ActionResult Index()
{
using (Database1Entities obj = new Database1Entities())
{
return View(obj.EMPs.ToList());
}
}
[HttpGet]
public ActionResult Create()
{
using (Database1Entities obj = new Database1Entities())
{
EMPVM vm = new EMPVM();
vm.LCOUNTRY = obj.COUNTRies.Select(m => new MetaData { ID = m.CID, NAME = m.CNAME }).ToList();
vm.LHOBBY = obj.HOBBies.Select(m => new MetaData { ID = m.HID, NAME = m.HNAME }).ToList();
vm.LINTEREST = obj.INTRESTs.Select(m => new MetaData { ID = m.IID, NAME = m.INAME }).ToList();
vm.LSTATE = new List<MetaData>();
return View(vm);
}
}
[HttpPost]
public ActionResult Create(EMPVM vm)
{
using (Database1Entities obj = new Database1Entities())
{
if (ModelState.IsValid)
{
EMP emp = new EMP();
emp.EID = vm.EID ?? 0;
emp.NAME = vm.NAME;
emp.PASSWORD = vm.PASSWORD;
emp.ADDRESS = vm.ADDRESS;
emp.SALARY = vm.SALARY;
emp.DOB = vm.DOB;
emp.EMAIL = vm.EMAIL;
emp.GENDER = vm.GENDER;
emp.CID = vm.COUNTRY;
emp.SID = vm.STATE;
obj.EMPs.Add(emp);
obj.SaveChanges();
foreach (MetaData md in vm.LHOBBY)
{
if (md.Selected)
{
HOBBYMAP hm = new HOBBYMAP();
hm.EID = vm.EID;
hm.HID = md.ID;
obj.HOBBYMAPs.Add(hm);
obj.SaveChanges();
}
}
foreach (string s in vm.INTEREST)
{
INTERESTMAP im = new INTERESTMAP();
im.EID = vm.EID;
im.IID = Convert.ToInt32(s);
obj.INTERESTMAPs.Add(im);
obj.SaveChanges();
}
return RedirectToAction("Index");
}
else
{
vm.LCOUNTRY = obj.COUNTRies.Select(m => new MetaData { ID = m.CID, NAME = m.CNAME }).ToList();
vm.LHOBBY = obj.HOBBies.Select(m => new MetaData { ID = m.HID, NAME = m.HNAME }).ToList();
vm.LINTEREST = obj.INTRESTs.Select(m => new MetaData { ID = m.IID, NAME = m.INAME }).ToList();
vm.LSTATE = obj.STATEs.Where(m => m.CID == vm.COUNTRY).Select(m => new MetaData { ID = m.SID, NAME = m.SNAME }).ToList();
return View(vm);
}
}
}
[HttpGet]
public ActionResult Edit(int id)
{
using (Database1Entities obj = new Database1Entities())
{
EMPVM vm = new EMPVM();
vm.LCOUNTRY = obj.COUNTRies.Select(m => new MetaData { ID = m.CID, NAME = m.CNAME }).ToList();
vm.LHOBBY = obj.HOBBies.Select(m => new MetaData { ID = m.HID, NAME = m.HNAME }).ToList();
vm.LINTEREST = obj.INTRESTs.Select(m => new MetaData { ID = m.IID, NAME = m.INAME }).ToList();
EMP emp=obj.EMPs.Find(id);
vm.LSTATE = obj.STATEs.Where(m => m.CID == emp.CID).Select(n => new MetaData { ID=n.SID,NAME=n.SNAME }).ToList();
vm.EID = emp.EID;
vm.NAME = emp.NAME;
vm.PASSWORD = emp.PASSWORD;
vm.CP = emp.PASSWORD;
vm.ADDRESS = emp.ADDRESS;
vm.SALARY = emp.SALARY;
vm.DOB = emp.DOB;
vm.EMAIL = emp.EMAIL;
vm.GENDER = emp.GENDER.Trim();
vm.COUNTRY = emp.CID??0;
vm.STATE = emp.SID??0;
List<int> lst = obj.HOBBYMAPs.Where(m => m.EID == id).Select(n =>n.HID.Value).ToList();
List<MetaData> hmd = obj.HOBBies.Where(n => lst.Contains(n.HID)).Select(m => new MetaData { ID=m.HID,NAME=m.HNAME,Selected=true }).ToList();
List<MetaData> hmd2 = obj.HOBBies.Where(n => lst.Contains(n.HID) == false).Select(m => new MetaData { ID = m.HID, NAME = m.HNAME, Selected = false }).ToList();
vm.LHOBBY = hmd.Union(hmd2).ToList();
List<string> ls=new List<string>();
foreach(int i in obj.INTERESTMAPs.Where(m=>m.EID==id).Select(n=>n.IID))
{
ls.Add(i.ToString());
}
vm.INTEREST = ls;
return View(vm);
}
}
[HttpPost]
public ActionResult Edit(EMPVM vm)
{
using (Database1Entities obj = new Database1Entities())
{
if (ModelState.IsValid)
{
EMP emp =obj.EMPs.Find(vm.EID);
emp.EID = vm.EID ?? 0;
emp.NAME = vm.NAME;
emp.PASSWORD = vm.PASSWORD;
emp.ADDRESS = vm.ADDRESS;
emp.SALARY = vm.SALARY;
emp.DOB = vm.DOB;
emp.EMAIL = vm.EMAIL;
emp.GENDER = vm.GENDER;
emp.CID = vm.COUNTRY;
emp.SID = vm.STATE;
obj.SaveChanges();
List<HOBBYMAP> lm=obj.HOBBYMAPs.Where(m => m.EID == vm.EID).ToList();
foreach (HOBBYMAP hm in lm)
{
obj.HOBBYMAPs.Remove(hm);
obj.SaveChanges();
}
foreach (MetaData md in vm.LHOBBY)
{
if (md.Selected)
{
HOBBYMAP hm = new HOBBYMAP();
hm.EID = vm.EID;
hm.HID = md.ID;
obj.HOBBYMAPs.Add(hm);
obj.SaveChanges();
}
}
List<INTERESTMAP> lm1=obj.INTERESTMAPs.Where(m => m.EID == vm.EID).ToList();
foreach (INTERESTMAP im in lm1)
{
obj.INTERESTMAPs.Remove(im);
obj.SaveChanges();
}
foreach (string s in vm.INTEREST)
{
INTERESTMAP im = new INTERESTMAP();
im.EID = vm.EID;
im.IID = Convert.ToInt32(s);
obj.INTERESTMAPs.Add(im);
obj.SaveChanges();
}
return RedirectToAction("Index");
}
else
{
vm.LCOUNTRY = obj.COUNTRies.Select(m => new MetaData { ID = m.CID, NAME = m.CNAME }).ToList();
vm.LHOBBY = obj.HOBBies.Select(m => new MetaData { ID = m.HID, NAME = m.HNAME }).ToList();
vm.LINTEREST = obj.INTRESTs.Select(m => new MetaData { ID = m.IID, NAME = m.INAME }).ToList();
vm.LSTATE = obj.STATEs.Where(m => m.CID == vm.COUNTRY).Select(m => new MetaData { ID = m.SID, NAME = m.SNAME }).ToList();
return View(vm);
}
}
}
public ActionResult Delete(int id)
{
using (Database1Entities obj = new Database1Entities())
{
EMP vm = obj.EMPs.Find(id);
obj.EMPs.Remove(vm);
obj.SaveChanges();
List<HOBBYMAP> lm = obj.HOBBYMAPs.Where(m => m.EID == vm.EID).ToList();
foreach (HOBBYMAP hm in lm)
{
obj.HOBBYMAPs.Remove(hm);
obj.SaveChanges();
}
List<INTERESTMAP> lm1 = obj.INTERESTMAPs.Where(m => m.EID == vm.EID).ToList();
foreach (INTERESTMAP im in lm1)
{
obj.INTERESTMAPs.Remove(im);
obj.SaveChanges();
}
return RedirectToAction("Index");
}
}
public JsonResult Check(DateTime? DOB)
{
DateTime dt = DateTime.Now;
int dif = dt.Subtract(DOB.Value).Days;
return Json(!(dif <= 0), JsonRequestBehavior.AllowGet);
//if(DOB!=null)
//{
// DateTime dt = DateTime.Now;
// int dif = dt.Subtract(DOB.Value).Days;
// return Json(!(dif <= 0), JsonRequestBehavior.AllowGet);
//}
// else
// return Json(null, JsonRequestBehavior.AllowGet);
}
public JsonResult Fillddl(int ID)
{
using (Database1Entities obj = new Database1Entities())
{
return Json(obj.STATEs.Where(m => m.CID == ID).Select(n => new MetaData { ID = n.SID, NAME = n.SNAME }).ToList(), JsonRequestBehavior.AllowGet);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Web.Mvc;
namespace MvcApplication2.Models
{
public class EMPVM
{
[Required(ErrorMessage = "Eid should not be blank.")]
public int? EID { get; set; }
[Required(ErrorMessage = "Name should not be blank.")]
public string NAME { get; set; }
[Required(ErrorMessage = "Password should not be blank.")]
[StringLength(8,MinimumLength=6,ErrorMessage="Password length between 6 to 8 charecters.")]
[DataType(DataType.Password)]
public string PASSWORD { get; set; }
[DisplayName("CONFIRM PASSWORD")]
[System.ComponentModel.DataAnnotations.Compare("PASSWORD",ErrorMessage="Confirm password must be same with passwrod.")]
[Required(ErrorMessage = "Confirm password should not be blank.")]
[DataType(DataType.Password)]
public string CP { get; set; }
[Required(ErrorMessage="Address should not be blank.")]
[DataType(DataType.MultilineText)]
public string ADDRESS { get; set; }
[Required(ErrorMessage = "Salary should not be blank.")]
[Range(5000,500000,ErrorMessage="Salary range between 5000 to 500000.")]
public decimal? SALARY { get; set; }
[Required(ErrorMessage = "Dob should not be blank.")]
[Remote("Check","Home",ErrorMessage="Dob should not greater than or equal to current date.")]
public DateTime? DOB { get; set; }
[Required(ErrorMessage = "Email should not be blank.")]
[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*",ErrorMessage="Invalid email Id.")]
public string EMAIL { get; set; }
[Required(ErrorMessage = "Gender should not be blank.")]
public string GENDER { get; set; }
[Hvalidate(ErrorMessage = "Please select a hobby.")]
[DisplayName("HOBBY")]
public List<MetaData> LHOBBY { get; set; }
[Ivalidate(ErrorMessage = "Please select a interest.")]
public List<string> INTEREST { get; set; }
public List<MetaData> LINTEREST{ get; set;}
[Required(ErrorMessage = "Please select a country.")]
public int COUNTRY { get; set; }
public List<MetaData> LCOUNTRY { get; set; }
[Required(ErrorMessage = "Please select a state.")]
public int STATE { get; set; }
public List<MetaData> LSTATE { get; set; }
public EMPVM()
{
LHOBBY = new List<MetaData>();
LINTEREST = new List<MetaData>();
LCOUNTRY = new List<MetaData>();
LSTATE = new List<MetaData>();
}
}
public class Hvalidate : ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null)
return false;
return ((List<MetaData>)value).Count(m=>m.Selected==true)>0;
}
}
public class Ivalidate:ValidationAttribute
{
public override bool IsValid(object value)
{
if (value == null)
return false;
return !(((List<string>)value).ToList().Count() == 0);
}
}
public class MetaData
{
public int ID { get; set; }
public string NAME { get; set; }
public bool Selected { get; set; }
}
public class MetaData1
{
public string NAME { get; set; }
}
}
Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication2.Models;
namespace MvcApplication2.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
[HttpGet]
public ActionResult Index()
{
using (Database1Entities obj = new Database1Entities())
{
return View(obj.EMPs.ToList());
}
}
[HttpGet]
public ActionResult Create()
{
using (Database1Entities obj = new Database1Entities())
{
EMPVM vm = new EMPVM();
vm.LCOUNTRY = obj.COUNTRies.Select(m => new MetaData { ID = m.CID, NAME = m.CNAME }).ToList();
vm.LHOBBY = obj.HOBBies.Select(m => new MetaData { ID = m.HID, NAME = m.HNAME }).ToList();
vm.LINTEREST = obj.INTRESTs.Select(m => new MetaData { ID = m.IID, NAME = m.INAME }).ToList();
vm.LSTATE = new List<MetaData>();
return View(vm);
}
}
[HttpPost]
public ActionResult Create(EMPVM vm)
{
using (Database1Entities obj = new Database1Entities())
{
if (ModelState.IsValid)
{
EMP emp = new EMP();
emp.EID = vm.EID ?? 0;
emp.NAME = vm.NAME;
emp.PASSWORD = vm.PASSWORD;
emp.ADDRESS = vm.ADDRESS;
emp.SALARY = vm.SALARY;
emp.DOB = vm.DOB;
emp.EMAIL = vm.EMAIL;
emp.GENDER = vm.GENDER;
emp.CID = vm.COUNTRY;
emp.SID = vm.STATE;
obj.EMPs.Add(emp);
obj.SaveChanges();
foreach (MetaData md in vm.LHOBBY)
{
if (md.Selected)
{
HOBBYMAP hm = new HOBBYMAP();
hm.EID = vm.EID;
hm.HID = md.ID;
obj.HOBBYMAPs.Add(hm);
obj.SaveChanges();
}
}
foreach (string s in vm.INTEREST)
{
INTERESTMAP im = new INTERESTMAP();
im.EID = vm.EID;
im.IID = Convert.ToInt32(s);
obj.INTERESTMAPs.Add(im);
obj.SaveChanges();
}
return RedirectToAction("Index");
}
else
{
vm.LCOUNTRY = obj.COUNTRies.Select(m => new MetaData { ID = m.CID, NAME = m.CNAME }).ToList();
vm.LHOBBY = obj.HOBBies.Select(m => new MetaData { ID = m.HID, NAME = m.HNAME }).ToList();
vm.LINTEREST = obj.INTRESTs.Select(m => new MetaData { ID = m.IID, NAME = m.INAME }).ToList();
vm.LSTATE = obj.STATEs.Where(m => m.CID == vm.COUNTRY).Select(m => new MetaData { ID = m.SID, NAME = m.SNAME }).ToList();
return View(vm);
}
}
}
[HttpGet]
public ActionResult Edit(int id)
{
using (Database1Entities obj = new Database1Entities())
{
EMPVM vm = new EMPVM();
vm.LCOUNTRY = obj.COUNTRies.Select(m => new MetaData { ID = m.CID, NAME = m.CNAME }).ToList();
vm.LHOBBY = obj.HOBBies.Select(m => new MetaData { ID = m.HID, NAME = m.HNAME }).ToList();
vm.LINTEREST = obj.INTRESTs.Select(m => new MetaData { ID = m.IID, NAME = m.INAME }).ToList();
EMP emp=obj.EMPs.Find(id);
vm.LSTATE = obj.STATEs.Where(m => m.CID == emp.CID).Select(n => new MetaData { ID=n.SID,NAME=n.SNAME }).ToList();
vm.EID = emp.EID;
vm.NAME = emp.NAME;
vm.PASSWORD = emp.PASSWORD;
vm.CP = emp.PASSWORD;
vm.ADDRESS = emp.ADDRESS;
vm.SALARY = emp.SALARY;
vm.DOB = emp.DOB;
vm.EMAIL = emp.EMAIL;
vm.GENDER = emp.GENDER.Trim();
vm.COUNTRY = emp.CID??0;
vm.STATE = emp.SID??0;
List<int> lst = obj.HOBBYMAPs.Where(m => m.EID == id).Select(n =>n.HID.Value).ToList();
List<MetaData> hmd = obj.HOBBies.Where(n => lst.Contains(n.HID)).Select(m => new MetaData { ID=m.HID,NAME=m.HNAME,Selected=true }).ToList();
List<MetaData> hmd2 = obj.HOBBies.Where(n => lst.Contains(n.HID) == false).Select(m => new MetaData { ID = m.HID, NAME = m.HNAME, Selected = false }).ToList();
vm.LHOBBY = hmd.Union(hmd2).ToList();
List<string> ls=new List<string>();
foreach(int i in obj.INTERESTMAPs.Where(m=>m.EID==id).Select(n=>n.IID))
{
ls.Add(i.ToString());
}
vm.INTEREST = ls;
return View(vm);
}
}
[HttpPost]
public ActionResult Edit(EMPVM vm)
{
using (Database1Entities obj = new Database1Entities())
{
if (ModelState.IsValid)
{
EMP emp =obj.EMPs.Find(vm.EID);
emp.EID = vm.EID ?? 0;
emp.NAME = vm.NAME;
emp.PASSWORD = vm.PASSWORD;
emp.ADDRESS = vm.ADDRESS;
emp.SALARY = vm.SALARY;
emp.DOB = vm.DOB;
emp.EMAIL = vm.EMAIL;
emp.GENDER = vm.GENDER;
emp.CID = vm.COUNTRY;
emp.SID = vm.STATE;
obj.SaveChanges();
List<HOBBYMAP> lm=obj.HOBBYMAPs.Where(m => m.EID == vm.EID).ToList();
foreach (HOBBYMAP hm in lm)
{
obj.HOBBYMAPs.Remove(hm);
obj.SaveChanges();
}
foreach (MetaData md in vm.LHOBBY)
{
if (md.Selected)
{
HOBBYMAP hm = new HOBBYMAP();
hm.EID = vm.EID;
hm.HID = md.ID;
obj.HOBBYMAPs.Add(hm);
obj.SaveChanges();
}
}
List<INTERESTMAP> lm1=obj.INTERESTMAPs.Where(m => m.EID == vm.EID).ToList();
foreach (INTERESTMAP im in lm1)
{
obj.INTERESTMAPs.Remove(im);
obj.SaveChanges();
}
foreach (string s in vm.INTEREST)
{
INTERESTMAP im = new INTERESTMAP();
im.EID = vm.EID;
im.IID = Convert.ToInt32(s);
obj.INTERESTMAPs.Add(im);
obj.SaveChanges();
}
return RedirectToAction("Index");
}
else
{
vm.LCOUNTRY = obj.COUNTRies.Select(m => new MetaData { ID = m.CID, NAME = m.CNAME }).ToList();
vm.LHOBBY = obj.HOBBies.Select(m => new MetaData { ID = m.HID, NAME = m.HNAME }).ToList();
vm.LINTEREST = obj.INTRESTs.Select(m => new MetaData { ID = m.IID, NAME = m.INAME }).ToList();
vm.LSTATE = obj.STATEs.Where(m => m.CID == vm.COUNTRY).Select(m => new MetaData { ID = m.SID, NAME = m.SNAME }).ToList();
return View(vm);
}
}
}
public ActionResult Delete(int id)
{
using (Database1Entities obj = new Database1Entities())
{
EMP vm = obj.EMPs.Find(id);
obj.EMPs.Remove(vm);
obj.SaveChanges();
List<HOBBYMAP> lm = obj.HOBBYMAPs.Where(m => m.EID == vm.EID).ToList();
foreach (HOBBYMAP hm in lm)
{
obj.HOBBYMAPs.Remove(hm);
obj.SaveChanges();
}
List<INTERESTMAP> lm1 = obj.INTERESTMAPs.Where(m => m.EID == vm.EID).ToList();
foreach (INTERESTMAP im in lm1)
{
obj.INTERESTMAPs.Remove(im);
obj.SaveChanges();
}
return RedirectToAction("Index");
}
}
public JsonResult Check(DateTime? DOB)
{
DateTime dt = DateTime.Now;
int dif = dt.Subtract(DOB.Value).Days;
return Json(!(dif <= 0), JsonRequestBehavior.AllowGet);
//if(DOB!=null)
//{
// DateTime dt = DateTime.Now;
// int dif = dt.Subtract(DOB.Value).Days;
// return Json(!(dif <= 0), JsonRequestBehavior.AllowGet);
//}
// else
// return Json(null, JsonRequestBehavior.AllowGet);
}
public JsonResult Fillddl(int ID)
{
using (Database1Entities obj = new Database1Entities())
{
return Json(obj.STATEs.Where(m => m.CID == ID).Select(n => new MetaData { ID = n.SID, NAME = n.SNAME }).ToList(), JsonRequestBehavior.AllowGet);
}
}
}
}
View
@model MvcApplication2.Models.EMPVM
@{
ViewBag.Title = "Create";
}
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>EMPVM</legend>
<div class="editor-label">
@Html.LabelFor(model => model.EID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.EID)
@Html.ValidationMessageFor(model => model.EID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.NAME)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.NAME)
@Html.ValidationMessageFor(model => model.NAME)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PASSWORD)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.PASSWORD)
@Html.ValidationMessageFor(model => model.PASSWORD)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CP)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CP)
@Html.ValidationMessageFor(model => model.CP)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ADDRESS)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ADDRESS)
@Html.ValidationMessageFor(model => model.ADDRESS)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SALARY)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SALARY)
@Html.ValidationMessageFor(model => model.SALARY)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DOB)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DOB)
@Html.ValidationMessageFor(model => model.DOB)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.EMAIL)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.EMAIL)
@Html.ValidationMessageFor(model => model.EMAIL)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.GENDER)
</div>
<div class="editor-field">
@Html.RadioButtonFor(model => model.GENDER,"Male")Male
@Html.RadioButtonFor(model => model.GENDER, "Female")Female
@Html.ValidationMessageFor(model => model.GENDER)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.LHOBBY)
</div>
<div class="editor-field">
@{
for (int i = 0; i < Model.LHOBBY.Count; i++)
{
@Html.HiddenFor(m=>m.LHOBBY[i].ID)
@Html.HiddenFor(m=>m.LHOBBY[i].NAME)
@Html.CheckBoxFor(m=>m.LHOBBY[i].Selected)
@Html.DisplayFor(m=>m.LHOBBY[i].NAME)<br />
}
}
@Html.ValidationMessageFor(model => model.LHOBBY)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.INTEREST)
</div>
<div class="editor-field">
@Html.ListBoxFor(model =>model.INTEREST,new SelectList(Model.LINTEREST,"ID","NAME"))
@Html.ValidationMessageFor(model => model.INTEREST)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.COUNTRY)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.COUNTRY, new SelectList(Model.LCOUNTRY, "ID", "NAME"), "Select", new { @id="ddl"})
@Html.ValidationMessageFor(model => model.COUNTRY)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.STATE)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.STATE, new SelectList(Model.LSTATE, "ID", "NAME"), "Select", new { @id="ddl1"})
@Html.ValidationMessageFor(model => model.STATE)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script type="text/javascript">
$(function () {
$('#ddl').change(function () {
$.ajax({
url: '/Home/Fillddl',
data: { ID: $('#ddl').val() },
type: 'Get',
success: function (data) {
$('#ddl1').empty();
$('#ddl1').append("<option value='0'>Select</option>");
$.each(data, function (i, j) {
$('#ddl1').append("<option value='"+j.ID+"'>"+j.NAME+"</option>");
});
}
});
});
});
</script>