Questions tagged [model-binders]
13 questions
190
votes
17 answers
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…

Johnny Oshika
- 54,741
- 40
- 181
- 275
138
votes
10 answers
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…

Sam Wessel
- 8,830
- 8
- 40
- 44
21
votes
3 answers
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)?

rafek
- 5,464
- 13
- 58
- 72
6
votes
3 answers
ASP.NET MVC - Multiple models in a form and model binders
I have a form which needs to populate 2 models. Normally I use a ModelBinderAttribute on the forms post action i.e.
[Authorize]
[AcceptVerbs("POST")]
public ActionResult Add([GigBinderAttribute]Gig gig, FormCollection formCollection)
…

iasksillyquestions
- 5,558
- 12
- 53
- 75
3
votes
2 answers
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…

jlembke
- 13,217
- 11
- 42
- 56
2
votes
2 answers
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.IList object graph to work with the binder. So in the sample…

Bernt
- 249
- 6
- 12
2
votes
1 answer
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…

Jonathan
- 32,202
- 38
- 137
- 208
1
vote
1 answer
TryUpdateModel not working with Dictionary
Assuming these classes\enums:
public enum Test
{
MyTest1 = 0,
MyTest2,
MyTest3,
}
public class Model
{
public Dictionary TestDictionary { get; set; }
public Dictionary StringDictionary { get; set;…

Amir Popovich
- 29,350
- 9
- 53
- 99
1
vote
2 answers
ASP.NET MVC - TryUpdateModel Not Working
This is my View:
@using (Html.BeginForm("Save", "Test", FormMethod.Post))
{

Subby
- 5,370
- 15
- 70
- 125
1
vote
3 answers
Add class to elements for values of attribute with Backbone.ModelBinder
I'm using Backbone.ModelBinder in a Backbone.js Marionette project. I've a scenario which I can't work out how to use ModelBinder to automatically update my model/UI.
My model has a 'status' string attribute, with multiple states. In this example…

Meirion
- 788
- 5
- 18
1
vote
2 answers
how can I bind a complex class to a view, while preserving my custom validation attributes?
In my project I have a model class that uses another class, like in the sample below.
One of the properties in the model depends for validation on on of the properties of a child object -- in this sample, LastName property depends for validation on…

Ian
- 170
- 1
- 6
1
vote
1 answer
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…

chugh97
- 9,602
- 25
- 89
- 136
0
votes
1 answer
Bind multiple models to a single view in backbone
I have 2 models as
var Info = Backbone.Model.extend({
defaults: {
name: '',
company: ''
},
initialize: function(){
console.log('Object of type Info created');
},
});
var Emp = Backbone.Model.extend({
…

user544079
- 16,109
- 42
- 115
- 171