問題很簡單,但我似乎無法解決它。我使用DevExpress組合框使用Razor引擎。MVC 3 DevExpress - 返回控制器的模型爲空
我有這樣的代碼:
MODEL:
public class TestModel
{
public string Name { get; set; }
public List<Role> Roles { get; set; }
}
public class Role
{
public int RoleId { get; set; }
public string RoleName { get; set; }
}
控制器
public ActionResult OpenTest()
{
TestModel tm = new TestModel();
tm.Roles = new List<Role>();
tm.Roles.Add(new Role() { RoleId = 1, RoleName = "Role 1" });
tm.Roles.Add(new Role() { RoleId = 2, RoleName = "Role 2" });
tm.Roles.Add(new Role() { RoleId = 3, RoleName = "Role 3" });
return View(tm);
}
在這裏,我可以成功打開視圖,並且精細顯示的數據:
VIEW
@model TestDx.Models.TestModel
@{
ViewBag.Title = "OpenTest";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.DevExpress().ComboBox(
settings =>
{
settings.Name = "TestDx.Models.TestModel.Roles";
settings.Width = 120;
settings.SelectedIndex = 0;
settings.Properties.DropDownWidth = 300;
settings.Properties.DropDownStyle = DevExpress.Web.ASPxEditors.DropDownStyle.DropDownList;
settings.Properties.EnableCallbackMode = false;
settings.Properties.CallbackPageSize = 30;
settings.Properties.IncrementalFilteringMode = DevExpress.Web.ASPxEditors.IncrementalFilteringMode.StartsWith;
settings.Properties.TextFormatString = "{0}";
settings.Properties.ValueField = "RoleID";
settings.Properties.ValueType = typeof(int);
settings.Properties.Columns.Add("RoleID", "RoleID", 10);
settings.Properties.Columns.Add("RoleName", "RoleName", 100);
}).BindList(Model.Roles).GetHtml()
<br />
@Html.DevExpress().Button(
settings =>
{
settings.Name = "btnSave";
settings.ClientEnabled = true;
settings.ControlStyle.CssClass = "button";
settings.ClientVisible = true;
settings.Text = "save";
settings.UseSubmitBehavior = true;
settings.ControlStyle.Font.Bold = true;
}).GetHtml()
}
現在,這一切都非常簡單,我沒有做任何事的,只是dispaying它。但是,當我點擊保存按鈕,我回到控制器,這種方法:
[HttpPost]
public ActionResult OpenTest([ModelBinder(typeof(DevExpressEditorsBinder))]TestModel model)
{
if (ModelState.IsValid)
{
//
}
return View(model);
}
...和型號這裏是空的,角色屬性爲0。我不明白這是爲什麼?事件組合框名稱與它所綁定的屬性相同,我確定使用推薦的DevExpress活頁夾。
謝謝。
如果知道相同的問題,可以很好地知道原因。 –