Questions tagged [defaultmodelbinder]

For questions about .NET API DefaultModelBinder Class

Useful links

101 questions
6
votes
5 answers

ASP.NET MVC Beta 1: DefaultModelBinder wrongly persists parameter and validation state between unrelated requests

When I use the default model binding to bind form parameters to a complex object which is a parameter to an action, the framework remembers the values passed to the first request, meaning that any subsequent request to that action gets the same data…
6
votes
2 answers

ASP.NET MVC UpdateModel with interface

I am trying to get UpdateModel to populate a model that is set as only an interface at compile-time. For example, I have: // View Model public class AccountViewModel { public string Email { get; set; } public IProfile Profile { get; set; } } //…
Brian Vallelunga
  • 9,869
  • 15
  • 60
  • 87
5
votes
1 answer

Manipulate model value before passing it to DefaultModelBinder.BindModel

Some decimal and decimal? properties in my view model are marked as "Percent" data type, along with other data annotations, for example: [DataType("Percent")] [Display(Name = "Percent of foo completed")] [Range(0, 1)] public decimal? FooPercent {…
Dave Mateer
  • 17,608
  • 15
  • 96
  • 149
5
votes
2 answers

MVC3 ModelBinding to a collection posted back with index gaps

I have a collection of objects on my Model that I'm rendering in a View by using EditFor function, and I have an EditorTemplate which is responsible for actually rendering each object. @Html.EditorFor(model => model.MyObjects) This has worked well…
5
votes
1 answer

Binding a string parameter to Enum type in AzureFunction

I am trying to bind a string route parameter to Enum Type like below public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "ValidateKey/{keyType}/{key}")]HttpRequestMessage req, KeyType…
5
votes
2 answers

Testing Model binding in ASP.NET MVC 2

First; I know that I should not need to test the internals of MVC but I REALLY need a suite a tests around data flowing into our system. How can I, I hope without mocking all of HTTP context, test that objectA (form collection, dict, collection,…
4
votes
2 answers

Do MVC3 non-sequential hidden input indexes need to come first?

MVC3 non-sequential index hidden inputs for model binding.. Does it matter if they go before, after, in the middle of the other related inputs to be posted? Does it matter at all where they end…
Benjamin
  • 3,134
  • 6
  • 36
  • 57
4
votes
1 answer

ASP.NET MVC auto-binds a refreshed model when ModelState is invalid on HttpPost

I'm working on an ASP.NET MVC2 app. I've come to realize a very surprising, yet amazing thing that MVC does behind the scenes having to do with the ModelState and model binding. I have a ViewModel which has a whole bunch of data - some fields being…
4
votes
3 answers

Asp.Net MVC 2 DefaultModelBinder error using abstract classes

I have a simple Poco-Model using abstract classes, and it seems not to work with the Default ModelBinder of Asp.net MVC 2. One Item has several Objects in a collection, all using the same abstract base class. Model: public partial class Item …
user250773
  • 569
  • 1
  • 8
  • 21
4
votes
3 answers

Decoration on ViewModel property to use a different name for binding

On MVC3, is there a way to decorate a ViewModel property in order to get the DefaultModelBinder to use a different name for it in the request? For example, suppose you have the following view model: public class SomeModel { public string…
Pablo Romeo
  • 11,298
  • 2
  • 30
  • 58
4
votes
1 answer

bindmodel vs createmodel asp mvc 3

I am developping my first application in Asp. I am using the environment Asp.NET MVC 3. I have a controller Action that has a single parameter. The type of this parameter is a complex object. public ActionResult MyAction(ComplexObj obj) { …
3
votes
1 answer

Model Binder & Hidden fields

I have a simplified test scenario useful for asking this question: A Product can have many Components, a Component can belong to many Products. EF generated the classes, I've slimmed them as follows: public partial class Product { public int Id…
ekkis
  • 9,804
  • 13
  • 55
  • 105
3
votes
1 answer

MVC 3 with Forms and Lists: default model binder and EditorFor

The Model: public class MyObject { public IList Entries; } public class Entry { public string Name { get; set; } } If I use the default EditorFor(model => model.Entries) the name/id values are:
Cymen
  • 14,079
  • 4
  • 52
  • 72
3
votes
1 answer

What should a BindModel() implementation do?

I've been reading the MVC 3 source code trying to understand what semantics I should adhere to if I override DefaultModelBinder.BindModel() or even implement IModelBinder.BindModel(). It's unclear to me what "state" BindModel() should leave other…
3
votes
1 answer

Model Binding Custom Type

I have a struct which works much like the System.Nullable type: public struct SpecialProperty { public static implicit operator T(SpecialProperty value) { return value.Value; } public static implicit operator…
Paul
  • 6,188
  • 1
  • 41
  • 63