本文整理汇总了C#中IModelBinder.BindModel方法的典型用法代码示例。如果您正苦于以下问题:C# IModelBinder.BindModel方法的具体用法?C# IModelBinder.BindModel怎么用?C# IModelBinder.BindModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModelBinder
的用法示例。
在下文中一共展示了IModelBinder.BindModel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModelBind
object ModelBind(ControllerContext controllerContext, ModelBindingContext bindingContext, IModelBinder binder = null)
{
if (this.Name != null) {
bindingContext.ModelName = this.Name;
}
// For action parameters, ValueProvider is ValueProviderCollection (composite).
// For controller properties (BindRouteProperties), it's null.
// That's why we always need to set it to the appropriate instance here.
bindingContext.ValueProvider = (ValueProviderFactories.Factories
.OfType<RouteDataValueProviderFactory>()
.FirstOrDefault()
?? new RouteDataValueProviderFactory())
.GetValueProvider(controllerContext);
if (binder == null) {
bool isDefaultBinder;
binder = GetModelBinder(this, bindingContext.ModelType, out isDefaultBinder);
}
return binder.BindModel(controllerContext, bindingContext);
}
示例2: GetPropertyValue
/// <summary>
/// Returns the value of a property using the specified controller context, binding context, property descriptor, and
/// property binder.
/// </summary>
/// <returns>
/// An object that represents the property value.
/// </returns>
/// <param name="controllerContext">
/// The context within which the controller operates. The context information includes the
/// controller, HTTP content, request context, and route data.
/// </param>
/// <param name="bindingContext">
/// The context within which the model is bound. The context includes information such as the
/// model object, model name, model type, property filter, and value provider.
/// </param>
/// <param name="propertyDescriptor">
/// The descriptor for the property to access. The descriptor provides information such as
/// the component type, property type, and property value. It also provides methods to get or set the property value.
/// </param>
/// <param name="propertyBinder">An object that provides a way to bind the property.</param>
protected override object GetPropertyValue(ControllerContext controllerContext,
ModelBindingContext bindingContext,
PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder)
{
if (!IsPersistentType(bindingContext.ModelType))
{
return base.GetPropertyValue(controllerContext, bindingContext, propertyDescriptor, propertyBinder);
}
var context = new NHModelBindingContext(bindingContext)
{
Wrapper = _wrapper
};
object value = propertyBinder.BindModel(controllerContext, context);
if (bindingContext.ModelMetadata.ConvertEmptyStringToNull && Equals(value, String.Empty))
{
return null;
}
return value;
}