2011-05-17 46 views
3

在我的Action中,当我使用TryUpdateModel时,出现System.MissingMethodException类型的错误。 我在我的Controller的几个地方使用这个没有问题,所以这意味着我的模型有问题?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被生成。我从这个类派生出来添加Attributes,然后在我的Model中使用它。

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); 
    } 

要检索DATAS发送

[HttpPost] 
    public ActionResult ModifieTypeOperation(Int64 idTypeOperation, FormCollection fc) 
    { 
     DetailTypeOperationModel d = new DetailTypeOperationModel(); 
     TryUpdateModel<DetailTypeOperationModel>(d); 

     _srvTypeOperation.Modifier(d.TypeOperationDisplay); 

     return View("Index", new AdministrationModel());    
    } 

而且它的这个动作,我有问题的TryUpdateModel。 随着一步一步的调试,我看不出为什么这个组件捕获一个错误,这个缺少的方法在哪里?

感谢您的帮助:)

回答

1

让您TypeOperationDisplay财产虚拟在DetailTypeOperationModel类。

public class DetailTypeOperationModel : ViewModelBase 
{ 
    public Int64 IdTypeOperation { get; set; } 
    public virtual TypeOperationDisplay TypeOperationDisplay { get; set; } 
} 

我猜在这里,但我的理论是,EF试图创建DetailTypeOperationModel的代理,而不能因为自己的类属性是不是虚拟的。

+0

我与NHibernate,但虚拟已解决我的问题。谢谢 :) – 2011-05-25 13:43:02

相关问题