public class HomeController : Controller { TestEntities t = new TestEntities(); // // GET: /Home/ public ActionResult Index() { var model = new emp(); var countryList = t.Prabs.ToList(); foreach (var country in countryList) { model.CountryList.Add(new SelectListItem() { Text = country.Name, Value = country.ID.ToString(), }); } return View(model); } [HttpPost] public ActionResult save(emp model) { if (ModelState.IsValid) { var m = new Rahul(); m.CountryID = model.counid; // here i got error like cannot implicitly convert type int to string m.DOB = model.DOB; t.Rahuls.Add(m); t.SaveChanges(); } return View("Index",model); }
using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using System.ComponentModel.DataAnnotations; namespace WebApplication18.Models { public class emp { public emp() { CountryList = new List<SelectListItem>(); } public int id { get; set; } public IList<SelectListItem> CountryList { get; set; } public int counid { get; set; } [DataType(DataType.Date)] public DateTime DOB { get; set; } } }
CountryID
model.counid
m.CountryID = Convert.ToString(model.counid)
Quote:i used this and error gone..
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)