当我点击更新按钮时,我得到了TestCaseModel md的空值。我无法得到我做错的地方。 (我试图获得组合框的选定值)
我的模特
public class TestCaseModel
{
public Product pro {get;set;}
public List<ProductCatagory> lst { get; set; }
}
public class Product {
public string Name { get; set; }
public string Description { get; set; }
}
public class ProductCatagory {
public string ID { get; set; }
public string Name { get; set; }
}
我的控制器
public ActionResult Index()
{
TestCaseModel md = new TestCaseModel();
md.lst = new List<ProductCatagory> {
new ProductCatagory { ID="1",Name="science book"},
new ProductCatagory {ID="2",Name="cartoon book"}
};
md.pro = new Product {Description="here is the des.",Name="Book" };
return View(md);
}
[HttpPost]
public ActionResult Update(TestCaseModel md)
{
X.Msg.Notify(new NotificationConfig
{
Icon = Icon.Accept,
Title = "Working",
Html = md.pro.Name+">>"
}).Show();
return this.Direct();
}
和我的观点
@Html.X().ResourceManager()
@Html.X().TextFieldFor(m=>m.pro.Name).Flex(1).FieldLabel("ID").Value(@Model.pro.Name)
@Html.X().ComboBox().FieldLabel("Urun katagori").Flex(1).Store(Html.X().Store().ID("Store41")
.Model(Html.X().Model().Fields(new ModelField("ID"), new ModelField("Name"))).DataSource(@Model.lst)
).ValueField("ID").DisplayField("Name").Value(@Model.pro.Name)
@Html.X().Button().Text("Update").Icon(Icon.PageSave).DirectClickAction("Update","TestCase")
答案 0 :(得分:1)
很难真正说出没有堆栈跟踪的代码有什么问题;
但是,考虑到你到目前为止所展示的内容,我会说如果你怀疑任何类都是问题,那么你应该尝试初始化构造函数中的类中的所有值。尝试以下方法:
public class TestCaseModel
{
public Product pro {get;set;}
public List<ProductCatagory> lst { get; set; }
public TestCaseModel(){
pro = String.Empty;
lst = new List<ProductCatagory>();
}
}
public class Product {
public string Name { get; set; }
public string Description { get; set; }
public Product(){
Name = String.Empty;
Description = String.Empty;
}
}
public class ProductCatagory {
public string ID { get; set; }
public string Name { get; set; }
public ProductCatagory (){
ID = String.Empty
Name = String.Empty;
}
}