Questions tagged [modelbinders]

263 questions
8
votes
3 answers

Get FormCollection out controllerContext for Custom Model Binder

I had a nice function that took my FormCollection (provided from the controller). Now I want to do a model bind instead and have my model binder call that function and it needs the FormCollection. For some reason I can find it. I thought it would…
RailRhoad
  • 2,128
  • 2
  • 25
  • 39
8
votes
1 answer

DefaultModelBinder and collection of inherited objects

I have an action method like this below. [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Form newForm) { ... } I have a model with the following classes, which I'd like to load the data from the ajax JSON data. public class Form { …
Thurein
  • 6,645
  • 5
  • 22
  • 23
7
votes
2 answers

Custom Model Binder for Complex composite objects HELP

I am trying to write a custom model binder but I'm having great difficulty trying to figure how to bind complex composite objects. this is the class I'm trying to bind to: public class Fund { public int Id { get; set; } public string…
Tony Carter
7
votes
3 answers

DataContract model binding to JSON in ASP.NET MVC Action Method Arguments

MVC3 comes out of the box with JsonValueProviderFactory() which is very handy for binding incoming JSON to a model. Unfortunately, I can't figure out how to setup model contracts with names that differ from the incoming JSON. For example:…
7
votes
2 answers

Example IModelBinderProvider implementation for ModelBinder constructor injection in MVC 3

I need to wire my custom ModelBinder up to my DI container in MVC 3, but I can't get it working. So. This is what I have: A ModelBinder with a constructor injected service. public class ProductModelBinder : IModelBinder{ public…
Christian Dalager
  • 6,603
  • 4
  • 21
  • 27
7
votes
1 answer

DefaultModelBinder Problem with nested levels + other binders

I have what I would think is a somewhat normal situation where I need to bind form posts to an "order" model. This model has a few levels of information to it: Order.Billing.FirstName Order.Billing.Address.City Order.Billing.Address.Country Using…
claco
  • 739
  • 1
  • 8
  • 18
7
votes
1 answer

MVVM and ModelBinders in the ASP.NET MVC Framework

I've got a series of views, each are typed to have their own ViewModel class which contains everything they need to display themselves, for example: public class CreateResourceViewModel { public Project Parent { get; set; } public…
Kieron
  • 26,748
  • 16
  • 78
  • 122
6
votes
1 answer

Where is the documentation for the standard ASP.NET MVC ModelBinder?

I don't seem to be able to find any authoritative, up-to-date (i.e. for 1.0 final) documentation for the capabilities of the standard model-binder in ASP.NET MVC, particularly with respect to binding complex objects involving collections (and the…
Will Dean
  • 39,055
  • 11
  • 90
  • 118
6
votes
2 answers

MVC3 Razor model binder and inherited collections

I hope I'm not missing something incredibly obvious here but is there any reason why model binder is always having trouble binding a view model that inherits from a collection? Lets say I want to show a paged list and display a combo box and add…
Ales Potocnik Hahonina
  • 2,977
  • 2
  • 26
  • 32
6
votes
1 answer

Is it OK for a Model Binder to do a Repository Lookup?

I am building an MVC application and am designing a custom model binder for a class; Essentially one of the fields of the model is an object that exists in the database, but it is proving very difficult to associate this with the appropriate objects…
Ciel
  • 17,312
  • 21
  • 104
  • 199
6
votes
3 answers

Model Binder in ASP.NET webforms

For number of years I did ASP.NET web forms development I was spoiled by a proprietary library, which allowed me to do things like: UpdateToObject(ControlsCollection, obj) UpdateFromObject(ControlsCollection, obj) Conceptually code did…
Sherlock
  • 1,022
  • 8
  • 19
6
votes
2 answers

Asp.Net MVC 2 - Iterate Through Form Values In Model Binder

I have a list of items in my form which are named like this... I want to create a custom…
Noob
  • 1,049
  • 1
  • 10
  • 20
6
votes
2 answers

asp.net mvc strongly typed view model with multiselect

I would like to know how i can bind my form values to my strongly typed view from a MultiSelect box. Obviously when the form submits the multi-select box will submit a delittemered string of my values selected...what is the best way to convert this…
Paul Hinett
  • 1,951
  • 2
  • 26
  • 40
6
votes
1 answer

What is the best way to parse dates in binder

Is it good approach in the model binder use the code like this: TryParseDate(result.AttemptedValue, format, out parsedDate) And then "format" is a variable with different (customer specific) date format. Like 12/31/2013 or 31.12.2013 or other…
Sergey
  • 7,933
  • 16
  • 49
  • 77
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
1 2
3
17 18