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
6
votes
1 answer

Custom parameter binding to bind partial parameters

I have a Web API 2 project and an other project, in which I have my Model classes and a BaseModel that is a base for all Models, as following, public class BaseModel { public string UserId { get; set; } } All the other models are derived from…
6
votes
1 answer

Case Insensitive Model Binding MVC 4

I would like my model binding to be case insensitive. I tried manipulating a custom model binder inheriting from System.web.Mvc.DefaultModelBinder, but I can't figure out where to add case insensitivity. I also took a look at IValueProvider, but I…
5
votes
1 answer

How can I handle large JSON input from Postmark in my MVC application?

This is related to this question, but in this case it's not something I am returning but rather the model binding. I am using Postmark to handle incoming emails, which posts to a page with a JSON payload. I have a model as below and an action that…
5
votes
3 answers

Dependency Inject for models

I'm sure someone has asked this before, but I'm struggling to find where. I'm using Ninject to remove dependencies from my controllers, along with a repository design pattern. As I understand it, one of the benefits of this approach is that I can…
5
votes
4 answers

A created a new CustomModelBinder from one that already worked. Why does the new one never get called to do any binding?

Can I do something like this? [HttpPost] public ActionResult Index(WizardViewModel wizard, IStepViewModel step) { Where I have the following in my global.asax.cs application_start ModelBinders.Binders.Add(typeof(IStepViewModel), new…
Doug Chamberlain
  • 11,192
  • 9
  • 51
  • 91
5
votes
1 answer

Binding a string parameter to Enum type in AzureFunction

I am trying to bind a string route parameter to Enum Type like below public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "ValidateKey/{keyType}/{key}")]HttpRequestMessage req, KeyType…
5
votes
1 answer

Post a List .net core 1.0

I'm building a dynamic form creator in .net core. A "form" will consist of many different form elements. So the form model will look something like this: public class FormModel { public string FormName {get;set;} public List
5
votes
1 answer

Can I register a custom model binder somewhere other than Global.asax?

It would be handy to limit the scope of a custom model binder for just a specific controller action method or its entire controller. Hanselman wrote a sentence that implied alternative locations for custom model binder registration but never seemed…
patridge
  • 26,385
  • 18
  • 89
  • 135
4
votes
1 answer

Custom model binder for inner model

I got a model like this: public class MainModel { public string Id {get;set;} public string Title {get;set;} public TimePicker TimePickerField {get;set;} } TimePicker is an inner model which looks like this: public class TimePicker { …
4
votes
0 answers

ASP.NET Core ModelBindingContext Uses Only 1 Value Provider (Ignores RouteDataValueProvider)

I'm currently converting a ASP.NET library to ASP.NET Core that's heavy on Model Binding, and one issue I'm unable to resolve is that for cases where a model binder wants to try and get values via Value Providers both from (From)Query and…
4
votes
1 answer

Custom Model binder :Can't bind parameter 'xxx' because it has conflicting attributes on it

I am using a custom model binder in order to put some custom logic in my model Binding. Here's my DTOs: public class TaskDto { public int Id { get; set; } [MaxLength(100), Required] public string Name { get; set; } public…
4
votes
1 answer

DataAnnotations validation in Custom Model Binder

I have written a custom model binder for List in my MVC project however I am now stuck in how to get this binder to validate against my DataAnnotations validation attributes. I have found some posts on the interwebs that talk about similar…
hermiod
  • 1,158
  • 4
  • 16
  • 27
4
votes
2 answers

Saving Dropdown list selection with Entity Framework in ASP.NET MVC solution

I'm looking for advice on a decent pattern for dropdown list selection and persistence of the selection with POCO EF please. I have a list of IEnumerable in my view model where Country is a POCO loaded via EF. There is an Address property…
4
votes
1 answer

Custom Validation Attribute with Custom Model Binder in MVC 2

I apologise for the amount of code I have included. I've tried to keep it to a minimum. I'm trying to have a Custom Validator Attribute on my model as well as a Custom Model binder. The Attribute and the Binder work great seperately but if I have…
griegs
  • 22,624
  • 33
  • 128
  • 205
4
votes
3 answers

How to bind complex properties within polymorphic model in Asp.Net MVC 4?

I need to create a dynamic input form based on a derived type but I cannot get complex properties bound properly when passed to the POST method of my controller. Other properties bind fine. Here is a contrived example of what I have: Model public…
davy
  • 4,474
  • 10
  • 48
  • 71
1 2
3
11 12