我有这样的下拉列表:
public class RegionLine
{
public Nullable<int> regionId { get; set; }
[Display(Name = "Województwo: ")]
public string regionName { get; set; }
}
和控制器:
public PartialViewResult getPersonalData()
{
var d = rm.GetAllRegionsMapper();
ViewBag.Regions = new SelectList(rm.GetAllRegionsMapper().ToList(), "regionId", "regionName", "-- select item --");
var user = um.GetUserByLoginMapper(User.Identity.Name);
return PartialView("getPersonalData", user);
}
[HttpPost]
public PartialViewResult UpdatePersonalData(UserLine user)
{
var usr = um.GetUserByLoginMapper(User.Identity.Name);
ViewBag.Regions = new SelectList(rm.GetAllRegionsMapper().ToList(), "regionId", "regionName", "-- select item --");
if (ModelState.IsValid)
{
int status = uda.UpdateEmployeesPersonalData(user.UserId, user.PersonalData.Name, user.PersonalData.LastName,
user.Address.City, user.Address.Street, user.Address.Region.regionId, user.Address.PostCode,
user.PersonalData.KeyWord);
return PartialView("getLabelsPersonalData", user);
}
return PartialView("getPersonalData", usr);
}
我的下拉列表的视图部分:
<tr>
<td>@Html.LabelFor(a => a.Address.Region.regionName)</td>
<td>@Html.DropDownListFor(a => a.Address.Region.regionId, (SelectList)ViewBag.Regions)</td>
</tr>
当我选择一些项目时,httppost regionId 始终为空。请帮忙。