通过更新 ViewModel 时
[HttpPost]
public ActionResult Edit(int id, AddressChooserEnum addressChooser, string btnSubmit, FormCollection fc)
{
var vm = new AddressViewModel(id, addressChooser, bool.FalseString);
vm.Address = this.repository.GetAddressById(id, addressChooser);
try
{
UpdateModel(vm);
this.repository.Save();
return RedirectToAction("Edit", "Customer", new { id = id });
}
catch (Exception e)
{
return View(vm);
}
}
一切正常。但我无法与创作合作
[HttpPost]
public ActionResult Create(int id, AddressChooserEnum addressChooser, string btnSubmit, FormCollection fc)
{
var vm = new AddressViewModel(id, addressChooser, bool.TrueString);
this.repository.AddAddress(); //What here? It's the simple Add method which needs an Address object.
this.repository.Save();
return View(vm);
}
我正在尝试使用“空”地址创建 AddressViewModel。但是如何将它与 FormCollection 一起存储呢?我可以以某种方式将 FormCollection 绑定到一个新的 Address 对象吗?然后添加应该工作。提前致谢。