"这个属性setter是过时的,因为它的值是从ModelMetadata.Model衍生现在&QUOT。 [英] "This property setter is obsolete, because its value is derived from ModelMetadata.Model now."

查看:107
本文介绍了"这个属性setter是过时的,因为它的值是从ModelMetadata.Model衍生现在&QUOT。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href=\"http://www.asp.net/learn/mvc/tutorial-39-cs.aspx\">http://www.asp.net/learn/mvc/tutorial-39-cs.aspx

我们正在使用上述指导来实施我们的ASP.NET MVC应用程序的一些验证。

We are using the above guide to implement some validation in our ASP.NET MVC app.

我们收到以下错误此属性setter是过时的,因为它的值是从ModelMetadata.Model派生了。不具有行号,它只是当爆炸pressing提交按钮,创建一个新的消息。

We receive the following error This property setter is obsolete, because its value is derived from ModelMetadata.Model now. which does not have a line number, it simply explodes when pressing the submit button to create a new message.

我们都不得不使用元数据的例子(见上面的指导下),因为对象在DBML生成的

We are having to use the MetaData example (See bottom of the guide above) because the objects are generated in the DBML

关于是什么导致错误有什么建议?

Any suggestions about what's causing the error?

推荐答案

当你创建一个新的ModelBindingContext您将收到此错误,然后尝试设置ModelType属性的在MVC 2 preVIEW 2或更高版本的。例如,在旧版本的MVC的自定义模型绑定一个单元测试,我不得不code这样的:

You will get this error when you create a new ModelBindingContext and then attempt to set the ModelType property, in MVC 2 preview 2 or higher. For example, in a unit test for a custom model binder in older versions of MVC, I had code like the following:

    internal static T Bind<T>(string prefix, FormCollection collection, ModelStateDictionary modelState) where T:class
    {
        var mbc = new ModelBindingContext()
        {
            ModelName = prefix,
            ModelState = modelState,
            ModelType = typeof(T),
            ValueProvider = collection.ToValueProvider()
        };
        IModelBinder binder = new MyModelBinder();
        var cc = new ControllerContext();
        return binder.BindModel(cc, mbc) as T;
    }

当我更新到MVC 2 preVIEW 2,我像你描述了同样的错误。此修复程序是要改变这种code这样:

When I updated to MVC 2 preview 2, I got the same error as you described. The fix was to change this code to this:

    internal static T Bind<T>(string prefix, FormCollection collection, ModelStateDictionary modelState) where T:class
    {
        var mbc = new ModelBindingContext()
        {
            ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(T)),
            ModelName = prefix,
            ModelState = modelState,
            ValueProvider = collection.ToValueProvider()
        };
        IModelBinder binder = new MyModelBinder();
        var cc = new ControllerContext();
        return binder.BindModel(cc, mbc) as T;
    }

请注意,我已删除ModelType的分配,并与分配ModelMetadata取而代之。 Visual Studio中应该告诉你哪个code线实际上是抛出这个错误。

Note that I have removed the assignment of ModelType, and replaced it with an assignment to ModelMetadata. Visual Studio should tell you which line of code is actually throwing this error.

这篇关于&QUOT;这个属性setter是过时的,因为它的值是从ModelMetadata.Model衍生现在&QUOT。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆