当前位置: 首页>>代码示例>>C#>>正文


C# IModelBinder.BindModel方法代码示例

本文整理汇总了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);
        }
开发者ID:brettveenstra,项目名称:MvcCodeRouting,代码行数:23,代码来源:FromRouteAttribute.cs

示例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;
        }
开发者ID:luqizheng,项目名称:Qi4Net,代码行数:40,代码来源:NHModelBinder.cs


注:本文中的IModelBinder.BindModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。