Questions tagged [modelbinders]

263 questions
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
2 answers

Route Parameter, Custom Model Binder or Action Filter?

Our ASP.NET MVC application allows an authenticated user to administer one or more "sites" linked to their account. Our Urls are highly guessible since we use the site friendly name in the URL rather than the Id…
Ben Foster
  • 34,340
  • 40
  • 176
  • 285
5
votes
4 answers

Which Method of Model Binding Has Best Unit Test Semantics in ASP.NET MVC?

Definitions In ASP.NET MVC, there are two ways to do model binding in an action. Let's call these the "Bind arguments way" and the "UpdateModel way." Both of them do almost exactly the same thing, and they do it in almost exactly the same way: …
Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
5
votes
4 answers

Modelbinding database entities in ASPNET MVC

I'm having trouble trying to think what the best way is to recreate a database object in a controller Action. I want to make use of ModelBinders so in my action I have access to the object via a parameter, rather than having to repeat code to get an…
Luke Smith
  • 23,504
  • 8
  • 29
  • 28
5
votes
2 answers

Using a custom model binder for an argument of a controller action

I have a controller action that looks like: public ActionResult DoSomethingCool(int[] someIdNumbers) { ... } I would like to be able to use a custom model binder the create that array of IDs from a list of checkboxes on the client. Is there a…
Jason Jackson
  • 17,016
  • 8
  • 49
  • 74
5
votes
2 answers

ASP.NET MVC Model Binding into a List

In my ASP.NET MVC site, part of a feature allows the user to enter the hours when a certain venue is open. I've decided to store these hours in a VenueHours table in my database, with a FK-to-PK relationship to a Venues table, as well as DayOfWeek,…
Maxim Zaslavsky
  • 17,787
  • 30
  • 107
  • 173
5
votes
6 answers

Is it okay to hit the database from a custom model binder?

Say I have an object that gets some data from HttpPost and some from the database. I think I want to allow the ModelBinder to go to the database/repository for the that data missing from the post. In practice, is this a good or bad idea?
Byron Sommardahl
  • 12,743
  • 15
  • 74
  • 131
5
votes
1 answer

asp.net MVC 1.0 and 2.0 currency model binding

I would like to create model binding functionality so a user can enter ',' '.' etc for currency values which bind to a double value of my ViewModel. I was able to do this in MVC 1.0 by creating a custom model binder, however since upgrading to MVC…
David
  • 15,150
  • 15
  • 61
  • 83
5
votes
1 answer

ASP.NET MVC 1.0 - Model binder for Dictionaries

I have a ViewModel class containing a Dictionary (and other irrelevant things for this question): public class MyViewModel { public Dictionary Data { get; set; } /* ... */ } Then I have a couple of GET/POST actions that deal…
Bruno Reis
  • 37,201
  • 11
  • 119
  • 156
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,…
5
votes
3 answers

Updating Parent/Child Records with model binders in ASP.Net MVC

I have modified the Nerd Dinner application to allow editing of child records by adding the following code to the DinnerForm.ascx

<%int i = 0; foreach (NerdDinner.Models.RSVP rsvp in this.Model.Dinner.RSVPs) { %> <%=…

KP.
  • 2,138
  • 23
  • 21
4
votes
2 answers

How can I provide my own ICustomTypeDescriptor in ASP.NET MVC?

I'm working on a small library for for ASP.NET MVC 3 that should offer better reusability of model metadata and easy mapping from data entities from / to custom viewmodels. For this I need to be able to provide my own implementation of…
Adrian Grigore
  • 33,034
  • 36
  • 130
  • 210
4
votes
5 answers

ASP.NET MVC UpdateModel empty property

Given the following Model, public class A { public string Name { get; set; } } public class B { public string Address { get; set; } public A InstanceOfA { get; set; } } View, <%= Html.TextBox("A.Name") %> and…
Neil
  • 1,301
  • 14
  • 27
4
votes
1 answer

Retrieving data from view, should I use model binder?

I am a bit lost here as I have not really looked at model binders so if possible, can one advise me if I am actually thinking about my problem correctly... :) and if my code is way of, please advise... 1 -I have a DTO class which contains 'custom…
Haroon
  • 3,402
  • 6
  • 43
  • 74
4
votes
2 answers

MVC3/4 Security & Model Binding for a dynamic object

I really need a second set of eyes on this so I'm hoping some of you can give me some feedback, I think I've been staring at it too long. I'm trying to setup a website using ASP.NET MVC3, and in this site I need the flexibility of creating dynamic…