Questions tagged [custom-model-binder]

The custom binding class needs to inherit form IModelBinder. Here we capture the current request and extract the Form fields individually. Then we can manipulate these fields any way we like.

Useful links

176 questions
2
votes
0 answers

ASP.NET MVC5 custom json model binder with html content

I used the FromJsonAttribute (created by Steve Sanderson), it's quite great, but sadly it doesn't pay attention to the AllowHtml attribute. I have the following model: public class HKNewsPaperViewModel { public int Id { get; set; } public…
Peter Hurtony
  • 472
  • 3
  • 17
2
votes
4 answers

MVC 3 Custom Model Binding To Flat Form Variable Structure

I'm having difficulty getting a Custom Model Binder working when the request contains a flat collection of form variables. I've got a ViewModel class that contains a nested ViewModel, e.g. public class ViewModel1 { public long Id { get; set; } …
Apogee
  • 276
  • 1
  • 11
2
votes
1 answer

Is it possible to get the Display Name back from a MVC custom model binder?

I have this code: public class MyModelBinder : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { string modelName =…
2
votes
1 answer

Set Items collection of ValidationContext on IValidatableObject?

I have a view model class that derives from IValidateableObject, and I am using the Validate method with ValidationContext to evaluate it from my controller. I would like to be able to test against more than the properties of the view model class…
DMC
  • 361
  • 4
  • 15
2
votes
1 answer

ASP.Net MVC Model Binding to JSON in EditorFor

I want to be able to pass information from my view model to my controller via JSON in hidden textboxes. I'm working with polygons in the Google maps API. As the user edits the polygon, I am storing the vertices in a hidden input via javascript. var…
Jason Butera
  • 2,376
  • 3
  • 29
  • 46
2
votes
2 answers

Validating a view model after custom model binding

I have a view model that implements IValidatableObject that contains a string and a collection of another view model, something like this: public sealed class MainViewModel { public string Name { get; set; } public…
Paul Aldred-Bann
  • 5,840
  • 4
  • 36
  • 55
2
votes
0 answers

Working with FlagsEnum, ModelBinders and JSON

How to modify the ModelBinder to work with FlagsEnum (Enum: byte)? I'll show the code: Code Enum [Flags] public enum TipoPessoaEnum : byte { Comprador = 1 , Proprietario = 2 , GerenteAgencia = 4 } Class public class…
ridermansb
  • 10,779
  • 24
  • 115
  • 226
2
votes
1 answer

How do I get access to my requests content in a custom model binder in Asp Net MVC 4 Web Api?

I have been thinking about how I can solve the problem I had in my previous question Can I get access to the data that the .net web api model binding was not able to handle? I'm thing that I can use my own custom model binder, that way I can handle…
David Kethel
  • 2,440
  • 9
  • 29
  • 49
2
votes
2 answers

Custom Model Binder Which Will Only Work In One Area of MVC Application

I've used custom model binders which are configured in the Global.asax file. Is it possible to only use this model binder under certain areas of the application? public class CreatorModelBinder : IModelBinder { public object…
ek_ny
  • 10,153
  • 6
  • 47
  • 60
2
votes
1 answer

MVC3 Model Binding with Castle

I am quite new to MVC. I am using an interface as a property for my model. I noticed that my Data Annotation Attributes were being ignored. I also got an error while submitting the form: Cannot create an instance of an interface. I soon figured…
1
vote
1 answer

Ninject/MVC3 Custom Model Binder - Error activating

I am trying to inject dependency to my session dictionary class into my controller's constructor. eg: public AccountController(ISessionDictionary sessionDictionary) { this.sessionDictionary = sessionDictionary; } In my global.asax…
1
vote
1 answer

One custom model binder to CreateModel and another to BindModel?

Background: In my MVC post back action methods I am receiving command objects rather than view models. The idea is that these command objects (which roughly equate to transaction scripts) will be set up and ready to execute upon entering the action…
1
vote
0 answers

CustomModelBinder on properties of a Dto class

I have a DtoClass which has properties of a specific class, I don't want to have a CustomModelBinder for the DtoClass but for the class of its properties; I am using asp.net core 3.1. My ModelBinder Class is: public class SessionIdModelBinder :…
1
vote
1 answer

Model binding for nested inherited objects .Net core

Is it possible to create custom model binder for nested inherited objects? I saw this article https://learn.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-5.0, but my case is more difficult, my objects are very…