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

问题描述

在我的应用程序中,我试图分割DateTime和DateTime字段,以便我可以在该日期放置一个jQuery日期选择器。我发现,但是我得到一个编译错误 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:

什么是我错过了什么?我创建了一个新类,并将他的代码放在我的项目中的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.

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的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 02:02