Questions tagged [defaultmodelbinder]

For questions about .NET API DefaultModelBinder Class

Useful links

101 questions
3
votes
1 answer

Need help using the DefaultModelBinder for a nested model

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 { …
user1228
3
votes
1 answer

MVC2 Modelbinder for List of derived objects

I want a list of different (derived) object types working with the Default Modelbinder in Asp.net MVC 2. I have the following ViewModel: public class ItemFormModel { [Required(ErrorMessage = "Required Field")] public…
user250773
  • 569
  • 1
  • 8
  • 21
3
votes
1 answer

How to sanitize JSON input parameters when using MVC4 ApiController?

I had built an HTML sanitizer based on AntiXSS to automatically sanitize user input strings by overriding the default model binder, which works fine on standard post requests. However when using the new ApiController the default model binder never…
Michael Brown
  • 1,585
  • 1
  • 22
  • 36
3
votes
1 answer

How to return HTTP status code form Custom Model Binder

I have a custom model binder which pulls an implementation of an interface from a MEF container. It is implemented as follows: public class PetViewModelBinder : DefaultModelBinder { public object BindModel(ControllerContext controllerContext,…
2
votes
0 answers

Not getting resource file from DefaultModelBinder.ResourceClassKey

In my MVC3 project, in Global.Application_Start(), I have System.Web.Mvc.DefaultModelBinder.ResourceClassKey = "DefaultModelBinder"; I also have 2 resource files in App_GlobalResources: DefaultModelBinder.resx DefaultModelBinder.fr.resx Why isn't…
getit
  • 623
  • 2
  • 8
  • 30
2
votes
1 answer

Custom Model Binder to bind nested property values

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…
Attila Kun
  • 2,215
  • 2
  • 23
  • 33
2
votes
1 answer

How do I get MVC Model Binder to only bind non Null values for a list?

Following this question I was wondering if there is anyway to make MVC model binder only bind elements to a list if there is a value to populate them. For example if have a form with three inputs with the same name and one value isn't entered how do…
2
votes
1 answer

How do I use (Try)UpdateModel?

What is the right way to use (Try)UpdateModel? When I run this: TryUpdateModel returns true, ViewData has no errors, but my Proxy is not updated. Action Method public void Save(string TypeName, int Id, FormCollection idontknow) { var types =…
2
votes
1 answer

MS MVC3 Model Binding an Object

Can someone help me better understand the DefaultModelBinder and how it handles binding a Model that has a property of type object? I've downloaded the code and tried tracing through it, but am still scratching my head a little. Let's say I have a…
2
votes
2 answers

.Net MVC3 Custom Model Binder - Initially Loading Model

I am creating a custom model binder to initially load a model from the database before updating the model with incoming values. (Inheriting from DefaultModelBinder) Which method do I need to override to do this?
kroehre
  • 1,104
  • 5
  • 15
2
votes
1 answer

InvalidOperationException Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexTypeModelBinder.CreateModel(ModelBindingContext bindingContext)

I am trying to bind a complex type to a property to edit the property values and save the changes in memory, for now for testing. I get an exception when I execute Post. This is my Edit razor view.

Edit:

Ahhzeee
  • 123
  • 1
  • 12
2
votes
1 answer

GetUtcOffset returns the wrong off set for certain years / dates

var currentServerOffset = TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(1972, 03, 19, 02, 00, 00); using the above returns the wrong offset, but when you pass through 26th March it is corrected. it seems that this is off for a whole week, in…
2
votes
1 answer

Default model binder does not bind my model class

I am trying to make a post that should use the Default Model Binder functionality in ASP.NET MVC 2 but unfortunately I can't get through.... When I click on the checkout button I populate a form dinamically using jQuery code and then submit this…
Lorenzo
  • 29,081
  • 49
  • 125
  • 222
2
votes
1 answer

MVC Default Model Binder - Bind a Multiselect Dropdown to an IList

I'm using MVC 2.0 in an ASP.NET application using NHibernate. I have a working View, Controller and data access layer using NHibernate that is able to display and save an entity with a relationship to another mapped entity: Person -- > Location It's…
bzarah
  • 358
  • 1
  • 9
2
votes
5 answers

Formatting nullable DateTime fields in strong typed View

I have a Person class with a BornDate property in my model defined as [DisplayName("Born Date")] public DateTime? BornDate { get; set; } I use this field in my view as <%= Html.LabelFor(model =>…
Lorenzo
  • 29,081
  • 49
  • 125
  • 222