关于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"; 展开
@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"; 展开
1个回答
展开全部
您DevExpress控件GridViewDataComboBoxColumn有否设置 ValueField="ID" TextField="Name"这属性?
<dx:GridViewDataComboBoxColumn Caption="部门" FieldName="Department
!Key">
<PropertiesComboBox DataSourceID="ds_Products" ValueField="ID" TextField="Name">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataComboBoxColumn Caption="部门" FieldName="Department
!Key">
<PropertiesComboBox DataSourceID="ds_Products" ValueField="ID" TextField="Name">
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询