将逗号分隔值绑定到模型属性MVC4

时间:2013-10-08 13:26:06

标签: c# asp.net-mvc-4

我的模特

public class txtbox 
{
    public string paramvalue {get;set;}
}

这里paramvalues =“0,5,10,15,20,25,30,35”;

视图 textbox.cshtml

@model.txtbox
@Html.textboxFor(x=>x.paramvalue)
@Html.HiddenFor(x=>x.paramValue)

模型绑定器

protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
        {
            var typeValue = bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".ModelType");
            var type = Type.GetType((string)typeValue.ConvertTo(typeof(string)),true);        
            var model = Activator.CreateInstance(type);         
            bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, type);
            return model;
        }

值未绑定到模型属性,这意味着当文本框中的值更改时,模型属性不会使用最新值进行更新。

任何人都可以帮我解决这个问题

0 个答案:

没有答案
相关问题