ValueProvider does not contain a definition for TryGetValue

前端 未结 2 818
青春惊慌失措
青春惊慌失措 2021-01-17 17:57

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

2条回答
  •  野的像风
    2021-01-17 18:58

    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;
        }
    }
    

    Update

    TryGetValue() is not an extension method, but rather it is a method on the type IDictionary. 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.

提交回复
热议问题