简体   繁体   English

TryUpdateModel和System.MissingMethodException

[英]TryUpdateModel and System.MissingMethodException

In my Action, I have an error of type System.MissingMethodException when I use TryUpdateModel. 在我的Action中,当我使用TryUpdateModel时,我有一个System.MissingMethodException类型的错误。 I use this in several place in my Controller without issue, so it mean a problem on my model ? 我在我的控制器中的几个地方使用它没有问题,所以这意味着我的模型有问题?

In this case, I use a derived class from my domain. 在这种情况下,我使用来自我的域的派生类。

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 is generated. 生成TypeOperation。 I derive from this class to add Attributes and I use this next in my Model. 我派从这个类添加属性,然后在我的模型中使用它。

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

To show, I use this Action 为了表明,我使用了这个动作

    public ActionResult AfficheDetailTypeOperation(Int64 idTypeOperation)
    {
        DetailTypeOperationModel d = new DetailTypeOperationModel
        {
            IdTypeOperation = idTypeOperation,
            TypeOperationDisplay = _srvTypeOperation.Charger(idTypeOperation).ToDisplay()
        };

        return View("GererTypeOperation", d);
    }

To retrieve datas sent 检索已发送的数据

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

        _srvTypeOperation.Modifier(d.TypeOperationDisplay);

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

And it's on this Action, that I have issue on TryUpdateModel. 这就是这个Action,我在TryUpdateModel上遇到了问题。 With step by step debug, I can't see why this component catch an error and where is this missing method ? 通过逐步调试,我看不出为什么这个组件捕获错误,这个缺少的方法在哪里?

Thanks for helping :) 谢谢你的帮助:)

Make your TypeOperationDisplay property virtual in your DetailTypeOperationModel class. 在DetailTypeOperationModel类中使您的TypeOperationDisplay属性成为虚拟

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

I am guessing here, but my theory is that EF is trying to create a proxy of DetailTypeOperationModel, and can't because your own class property is not virtual. 我在这里猜测,但我的理论是EF正在尝试创建DetailTypeOperationModel的代理,而不能因为你自己的类属性不是虚拟的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM