Questions tagged [imodelbinder]
27 questions
28
votes
4 answers
Best Practices when Implementing IModelBinder
I'm looking for a set of best practices to use when implementing IModelBinder.
I've read three different MVC books and each one does some slightly different stuff in their implementations without any real explanation.
The Hanselman, Haack, Guthrie,…
nikmd23
- 8,899
- 4
- 40
- 55
25
votes
4 answers
How do I create a custom model binder using the `BindModel(HttpActionContext actionContext...` signature?
I need to know how to create a custom IModelBinder in MVC 4 and it has been changed.
The new method that has to be implemented is :
bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext);
Mohammad HS Farvashani
- 465
- 1
- 4
- 13
8
votes
1 answer
ASP.NET MVC - Custom model binder able to process arrays
I need to implement a functionality to allow users to enter price in any form, i.e. to allow 10 USD, 10$, $10,... as input.
I would like to solve this by implementing a custom model binder for Price class.
class Price { decimal Value; int ID; }…
Marek
- 10,095
- 7
- 64
- 105
5
votes
2 answers
MVC 2, IModelBinder & ValueProvider changes
I'm trying to migrate to ASP.Net MVC 2 and meet some issues.
Here is one :
I needed to bind directly a Dictionary as result of a view post.
In ASP.Net MVC 1 it worked perfectly using a custom IModelBinder :
///
/// Bind Dictionary
Mose
- 1,671
- 3
- 15
- 33
5
votes
2 answers
IModelBinder and ASP.NET MVC Beta
Does anyone have links to tutorials regarding the new IModelBinder in asp.net mvc beta?
I can't get my head around it properly, so much has changed.
Thanks
kitsune
- 11,098
- 13
- 54
- 77
3
votes
2 answers
Asp.net MVC2 IModelBinder is trying to drive me nuts (and succeeding)
Let's say I have
class FooClass { }
class BarClass
{
public FooClass Foo;
}
This BarClass is the Model I'm passing to the ViewPage.
I'm also passing (via ViewData) an IEnumerable with all the Foo in it, and the one that match…
Sebastien F.
- 1,380
- 1
- 18
- 35
3
votes
2 answers
How do I invoke UpdateModel from within a Custom ModelBinder? (MVC)
I'm creating a few custom binders for complex types in my Model. My model is composed of objects that have their own separate binders. I want the base object to do its dirty work and then populate the complex object it encapsulates by passing off…
Justin
- 10,107
- 14
- 56
- 76
3
votes
3 answers
mvc6 custom model binder not firing
I'm trying to figure out model binding in current mvc6 (visual studio 2015 release candidate).
This is what my code looks like so far:
public class MyObjectModelBinder : IModelBinder
{
public Task…
Plaga
- 73
- 1
- 7
3
votes
1 answer
How to return HTTP status code form Custom Model Binder
I have a custom model binder which pulls an implementation of an interface from a MEF container. It is implemented as follows:
public class PetViewModelBinder : DefaultModelBinder
{
public object BindModel(ControllerContext controllerContext,…
psaxton
- 1,494
- 16
- 22
2
votes
1 answer
Can I automatically trigger model validation inside a custom model binder?
I have a complex object that I'm binding off of a form. The model binder looks like this:
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var form = new MyForm();
var myObject =…
Matt Mills
- 8,209
- 6
- 32
- 59
2
votes
1 answer
Extending Sanderson's custom mvc ModelBinder for an object stored in session
In his wonderful MVC book Steven Sanderson gives an example of a custom model binder that sets and retrieves a session variable, hiding the data storage element from the controller.
I'm trying to extend this to cater for a pretty common scenario:…
Central Scrutinizer
1
vote
1 answer
Custom IModelBinder and Database Access
For a user object in my asp.net mvc project, I have written a custom modelbinder to check whether passwords are valid and whether two matching passwords were entered etc..
The login name needs to be unique though, I was wondering whether I can check…
Morph
- 1,729
- 1
- 18
- 23
1
vote
0 answers
Abstract class and IModelBinder, how to get a correct ValidationState?
Context:
I have an angular App which send complex Data to my .net Core API. Data sent could be an Image (ImageDto) or a couple of Images (StackImageDto), and Title & Tags. We send Data using multi-part HTML form, It means the Data is not JSON…
Cedric Arnould
- 1,294
- 15
- 38
1
vote
0 answers
autofac and webapi 2 ModelBinder called twice - second time with an empty bindingContext.ModelName
I have the following configuration:
builder.RegisterWebApiModelBinderProvider();
RegisterModelBinder(config, builder).InstancePerLifetimeScope();
Which uses the following method:
private static IRegistrationBuilder
ash_s
- 75
- 1
- 6
1
vote
2 answers
My OWIN application is not triggering my custom model binder
I have some dates that come in a weird format (dd.MM.YYYY). This is something how the business wants it displayed. So, I need a custom model binder to read this date. I had this solution working fine, but when I switched over to using OWIN, then…
Kingsingh
- 11
- 2