ValueProvider不包含TryGetValue的定义 [英] ValueProvider does not contain a definition for TryGetValue

查看:172
本文介绍了ValueProvider不包含TryGetValue的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我试图分割DateTime和DateTime字段,以便我可以在该日期放置一个jQuery日期选择器。我发现 Hanselman的代码分割DateTime ,但是我得到一个编译错误 bindingContext.ValueProvider.TryGetValue(modelName,out valueResult); 。我得到的错误是:

In my application, I am trying to split the Date and Time from and DateTime field so I can put a jQuery date picker on the date. I found Hanselman's code for splitting the DateTime, however I get a compile error on bindingContext.ValueProvider.TryGetValue(modelName, out valueResult);. The error I get is:


错误3'System.Web.Mvc.IValueProvider'不包含'TryGetValue'的定义,没有可以找到扩展方法'TryGetValue'接受类型'System.Web.Mvc.IValueProvider'的第一个参数(您是否缺少using指令或程序集引用?)C:\Documents and Settings\xxx\My Documents \Visual Studio 2008\Projects\MyProject\Project\Helpers\DateAndTimeModelBinder.cs 83 42项目

Error 3 'System.Web.Mvc.IValueProvider' does not contain a definition for 'TryGetValue' and no extension method 'TryGetValue' accepting a first argument of type 'System.Web.Mvc.IValueProvider' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\xxx\My Documents\Visual Studio 2008\Projects\MyProject\Project\Helpers\DateAndTimeModelBinder.cs 83 42 Project

什么是我错过了什么?我创建了一个新类,并将他的代码放在我的项目中的Helpers文件夹中。

What am I missing something? I created a new class and put his code in a Helpers folder in my project.

推荐答案

TryGetValue()不是 System.Web.Mvc.IValueProvider 。我怀疑他有一个自定义的扩展名,如下所示:

TryGetValue() is not a member of System.Web.Mvc.IValueProvider. I suspect he has a custom extension which looks something like:

public static bool TryGetValue(this IValueProvider valueProvider, string key, out ValueProviderResult result) {
    try {
        result = valueProvider.GetValue(key);
        return true;
    }
    catch {
        result = null;
        return false;
    }
}

更新

TryGetValue()不是一个扩展方法,而是一种类型为IDictionary的方法 < T,U> 。从MVC1开始,因为@mootinator指示,类型 bindingContext.ValueProvider 已更改。可以忽略对 TryGetValue()的调用,而是调用 GetValue()并检查结果为null 。我不知道是否会抛出异常,因为我没有测试过,所以先尝试一下。

TryGetValue() is not an extension method, but rather it is a method on the type IDictionary<T,U>. The type of bindingContext.ValueProvider has changed since MVC1 as @mootinator indicated. It's possible you can just ignore the call to TryGetValue() and instead call GetValue() and check the result for null. I'm not sure if it will throw an exception as I haven't tested it, so try that first.

这篇关于ValueProvider不包含TryGetValue的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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