model-binders

How to test custom Model Binders in ASP.NET MVC?

I've written some custom model binders (implementing IModelBinder) in our ASP.NET MVC application. I'm wondering what is a good approach to unittest them (binders)? ...

Asp.net MVC Module binding with validation for Complex Types

I'm building a questionnaire app in asp.net mvc, and I'm having trouble with the module binder for a list of complex types. First: I can't get Questionnaire.IList<QuestionGroup>.IList<Question> object graph to work with the binder. So in the sample code below i use only one level IList. Second: I would love to pass in my repository/...

MVC DateTime binding with incorrect date format

Asp.net-MVC now allows for implicit binding of DateTime objects. I have an action along the lines of public ActionResult DoSomething(DateTime startDate) { ... } This successfully converts a string from an ajax call into a DateTime. However, we use the date format dd/MM/yyyy; MVC is converting to MM/dd/yyyy. For example, submitting a...

Model binder in MVC question

I am getting the following Error The model item passed into the dictionary is of type 'MvcWebApplication.Models.Product' but this dictionary requires a model item of type 'MvcWebApplication.ViewModels.ProductCommonViewModel'. Controller Code is as follows:- public ActionResult Index([Bind(Prefix= "MvcWebApplication.ViewModels.ProductC...

MVCContrib grid and posting back with model binder

The contents of my MVCContrib grid come from the Model on a strongly typed View. When a post is made, the contents of the grid are not in the model object when it returns to the controller. I can see that this is because the grid renders as just a table with text in cells. Is there something I can do so that when the post occurs, the li...

Doing custom binding for a specific data-type in a ModelBinder

I'm in the process of creating my own custom ModelBinder that inherits from DefaultModelBinder, and manually binds XElement-typed properties. Now it seems that I have to override the 'BindProperty' method, like so: protected override void BindProperty( ControllerContext controllerContext, ModelBindingContext bindin...

ASP.NET MVC: Best way to trim strings after data entry. Should I create a Custom Model Binder?

I'm using ASP.NET MVC and I'd like all user entered string fields to be trimmed before they're inserted into the database. And since I have many data entry forms, I'm looking for an elegant way to trim all strings instead of explicitly trimming every user supplied string value. I'm interested to know how and when people are trimming s...