defaultmodelbinder

Decimal values with thousand separator in Asp.Net MVC

三世轮回 提交于 2019-12-17 10:52:23
问题 I have a custom model class which contains a decimal member and a view to accept entry for this class. Everything worked well till I added javascripts to format the number inside input control. The format code format the inputted number with thousand separator ',' when focus blur. The problem is that the decimal value inside my modal class isn't bind/parsed well with thousand separator. ModelState.IsValid returns false when I tested it with "1,000.00" but it is valid for "100.00" without any

Need help using the DefaultModelBinder for a nested model

…衆ロ難τιáo~ 提交于 2019-12-12 16:15:39
问题 There are a few related questions, but I can't find an answer that works. Assuming I have the following models: public class EditorViewModel { public Account Account {get;set;} public string SomeSimpleStuff {get;set;} } public class Account { public string AccountName {get;set;} public int MorePrimitivesFollow {get;set;} } and a view that extends ViewPage<EditorViewModel> which does the following: <%= Html.TextBoxFor(model => model.Account.AccountName)%> <%= Html.ValidationMessageFor(model =>

DefaultModelBinder: IList vs List

我只是一个虾纸丫 提交于 2019-12-12 04:58:14
问题 I'm not sure if this is a bug, or a feature. I have an action param that takes a ListRequest object with a few string properties. .NET MVC dutifully maps the query string params of the same name to the ListRequest objects' properties. I add a ListRequest.Filters property, which is to be a list of strings taken from the querystring: ?filter=foo&filter=bar If I declare .Filters as a Get/Set of type List(Of String), DefaultModelBinder does exactly what you would expect. However, if I declare

Asp.net MVC Model binding derived class

守給你的承諾、 提交于 2019-12-11 12:13:27
问题 I've write an abstract class PaymentMethod and 2 derived classes, PaymentMethodInvoice and PaymentMethodBilling . For each of them i've write shared EditorTemplates. The GET works fine, I select my PaymentMethod and get the right form. If I POST this form the model binding doesn't work, it trys to instantiate the abstract class PaymentMethod . Must I override the CreateModel ( protected override object CreateModel )[1] or is there a better solution to handle this? [1] MVC 3 Model Binding a

.NET MVC: how to get the model binder to assign null to a list property?

 ̄綄美尐妖づ 提交于 2019-12-11 10:31:46
问题 I have a model like so: class Model { public IList<Item> Items { get; set; } } class Item { public int Id { get; set; } } I am sending a request to an action method that takes a Model as a parameter. The request contains the following key-value pair: " Items=" (i. e. Items=null ). The default model binder sets Items to be a list of 1 null item, where I want the list property itself to be null (or at least empty). Is there any way to accomplish this? Obviously, I could do some sort of custom

ASP.NET MVC Issue with Using Reflection Created Objects with the Default Model Binder

人走茶凉 提交于 2019-12-11 05:34:36
问题 I am having a weird issue in ASP.NET MVC with objects not being updated with UpdateModel when passed a formCollection . UpdateModel does not appear to be working properly when the object being updated is created through reflection. Scenario: I have an application which has approximately 50 lookup tables--each of which includes exactly the same schema including typical fields like id, title, description, isactive, and createdon. Rather than build 50 views, I wanted to have a single view which

Custom Model Binder to bind nested property values

和自甴很熟 提交于 2019-12-11 02:03:27
问题 The reason I need this: In one of my controllers I want to bind all Decimal values in a different way than the rest of my application. I do not want to register a Model Binder in Global.asax (via ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder()); ) I have tried deriving from the DefaultModelBinder class and override its BindProperty method, but that only works for the model instance's immediate (not nested) Decimal properties. I have the following example to demonstrate my

ASP.NET MVC 3 Validation on Nested Objects not working as expected - validates child object twice and not parent object

白昼怎懂夜的黑 提交于 2019-12-09 17:38:58
问题 I am trying to get ASP.NET MVC 3 to generate forms from complex, nested objects. There is one validation behaviour I found which was unexpected and I am not sure if it's a bug in the DefaultModelBinder or not. If I have two objects, lets call the "parent" one "OuterObject", and it has a property of type "InnerObject" (the child): public class OuterObject : IValidatableObject { [Required] public string OuterObjectName { get; set; } public InnerObject FirstInnerObject { get; set; } public

.NET core custom and default binding combined

主宰稳场 提交于 2019-12-07 04:00:48
问题 I'm creating a custom model binder for a view model, implementing IModelBinder I have a lot of properties in my view model, the majority of which do not need any custom binding. Rather than explicitly set all of the property values on my model individually from the ModelBindingContext , I would to be able to get the framework to bind the model for me, then I would carry out any custom binding: public class ApplicationViewModelBinder : IModelBinder { public Task BindModelAsync

DefaultModelBinder cannot deserialize .NET Dictionary object passed to an action as a JSON object?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 03:41:58
问题 I have a very simple class: public class FilterItem { public Dictionary<string, string> ItemsDictionary { get; set; } public FilterItem() { ItemsDictionary = new Dictionary<string, string>(); } } I want to populate the data in the dictionary on the client and then pass it to my controller action as a JSON object. However no matter what I try on the client, the DefaultModelBinder does not seem to be able to deserialize it. Here is an example javascript code to call my action: var