2011-05-17 47 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

相關問題