请参阅附加的图像。 我使用动态DropDownList显示国家,州&城市在我的Add_New组织形式。我正在从SQL数据库中检索DropDownList项目。动态DropDownList中的问题使用JQuery
问题是,当我点击提交按钮时,它将ID存储到数据库中,而不是DropDownList项的文本。
请帮我我已经尝试了很多解决方案,但问题仍然存在。 控制器将数据保存:
[HttpPost]
Public ActionResult Addnew(Organiztioninfo org)
{
db.Organiztioninfoes.Add(org);
db.SaveChanges();
return View();
}
//Organization Info is my table name. I am using Entity Framework
控制器用于检索国家列表数据表格数据库:
Public JsonResult Details()
{
var country = db.countries.ToList();
//countries is database table name holding list of countries
List<SelectListItems> licountry = new List<SelectListItems>();
foreach(var u in country)
{
licountry.Add(new SelectListItems{Text = u.Name, Value= u.ID.ToString()});
}
return Json(new SelectList(licountry, "Value", "Text",
JsonRequestBehaviour.AllowGet))
}
//Same Methods are implemented for populating State & Cities list..
DropDownList-Code|| J Query-Dynamic List||
将数据保存到数据库的代码在哪里?你是否将数据保存在同一个表中? –
我有一个在HTTP POST请求上调用的控制器方法。 – Ali
您能分享该代码吗?使用代码更新原始帖子...请勿在评论中分享代码.. –