关于DevExpress13.1 Combobox SP.NET MVC3 View中 引入Combobox 后部门 "ID" 无法传入Controller中 求解

View代码:@Html.DevExpress().ComboBox(settings=>{settings.Name="DeptID";settings.Propert... View代码:
@Html.DevExpress().ComboBox(settings =>
{
settings.Name = "DeptID";
settings.Properties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
settings.Properties.DropDownStyle = DropDownStyle.DropDownList;
settings.Properties.TextField = "Name";
settings.Properties.ValueField = "ID";
}).BindList(ViewBag.Departments).GetHtml()

Controller代码:
public ActionResult Add(User user)
{
userService.Add(user); //断点 user.DeptID = 0 ?
return View("Index");
}

Model:
[Table("Department")]
public class Department
{
[Key]
public int ID { get; set; }
[Required]
public string Name { get; set; }
}

[Table("User")]
public class User
{
[Key]
public string UserID { get; set; }
[Required]
public string UserName { get; set; }
public string Password { get; set; }
[Required]
public string UserRight { get; set; }
[Required]
public int DeptID { get; set; }
[ForeignKey("DeptID")]
public Department Department { get; set; }
}

要是写成这样就可以传入,但页面选项就变成ID号了
settings.Properties.TextField = "ID";
settings.Properties.ValueField = "Name";
展开
 我来答
cn1456cbt
2017-01-05 · TA获得超过983个赞
知道小有建树答主
回答量:797
采纳率:72%
帮助的人:259万
展开全部
您DevExpress控件GridViewDataComboBoxColumn有否设置 ValueField="ID" TextField="Name"这属性?

<dx:GridViewDataComboBoxColumn Caption="部门" FieldName="Department
!Key">
<PropertiesComboBox DataSourceID="ds_Products" ValueField="ID" TextField="Name">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式