在我的操作中,当我使用TryUpdateModel时,出现了类型为System.MissingMethodException的错误。我在控制器中的多个位置使用它而没有问题,这意味着问题出在我的模型上吗?
在这种情况下,我使用了从我的域派生的类。
public class TypeOperationDisplay : TypeOperation
{
public TypeOperationDisplay(TypeOperation to)
{
Id = to.Id;
Code = to.Code;
Libelle = to.Libelle;
LibelleSaisie = to.LibelleSaisie;
}
[ScaffoldColumn(false)]
public override long Id
{
get
{
return base.Id;
}
set
{
base.Id = value;
}
}
[HtmlPropertiesAttribute(MaxLength=255, Size=50, ReadOnly=true)]
[DisplayName("")]
public override string Code
{
get
{
return base.Code;
}
set
{
base.Code = value;
}
}
}
TypeOperation被生成。我从这个类派生出来添加属性,然后在我的模型中使用它。
public class DetailTypeOperationModel : ViewModelBase
{
public Int64 IdTypeOperation { get; set; }
public TypeOperationDisplay TypeOperationDisplay { get; set; }
}
为了展示,我使用这个动作。
public ActionResult AfficheDetailTypeOperation(Int64 idTypeOperation)
{
DetailTypeOperationModel d = new DetailTypeOperationModel
{
IdTypeOperation = idTypeOperation,
TypeOperationDisplay = _srvTypeOperation.Charger(idTypeOperation).ToDisplay()
};
return View("GererTypeOperation", d);
}
获取发送的数据
[HttpPost]
public ActionResult ModifieTypeOperation(Int64 idTypeOperation, FormCollection fc)
{
DetailTypeOperationModel d = new DetailTypeOperationModel();
TryUpdateModel<DetailTypeOperationModel>(d);
_srvTypeOperation.Modifier(d.TypeOperationDisplay);
return View("Index", new AdministrationModel());
}
在这个Action中,我在TryUpdateModel上遇到了问题。通过逐步调试,我看不出为什么这个组件会捕获错误以及缺少哪个方法?
感谢您的帮助 :)