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

How do I re-validate my model in a custom model binder inheriting from DefaultModelBinder after modifying it?

I have a custom model binder inheriting from DefaultModelBinder. What I want it to do is to set a property on the model, that can't be resolved by the DefaultModelBinder. It looks like this: public class FooModelBinder : DefaultModelBinder { …
3
votes
2 answers

How can I build a custom model binder which will return different types of models depending on the request context?

I have incoming requests (from Facebook for Credits handling) on a specific action which will have have different contents, so I have different model classes to handle that. This is my action: public ActionResult…
Marc
  • 6,749
  • 9
  • 47
  • 78
3
votes
1 answer

How to read the raw json post body before hitting the controller in dot net c#?

I need to implement a [HttpPost] web api with same route/uri, but more than 10 different combinations of parameters in json body. In which some parameters are null in some case but required in another case. As I am migrating an already deployed…
3
votes
1 answer

NullReferenceException when using custom model binder

I am trying to make a binder for an abstract class. The binder decides which implementation of the class to use. public abstract class Pet { public string name { get; set; } public string species { get; set; } abstract public string talk…
semaz
  • 115
  • 7
3
votes
1 answer

Asp.Net Core comma separated array in query string binder

I'm trying to implement custom binder to allow comma separated list in query string. Based on this blog post and official documentation I have created some solution. But instead of using attributes to decorate wanted properties I want to make this…
Artur
  • 4,595
  • 25
  • 38
3
votes
2 answers

MVC Model Binding Dynamic List of Lists

I have a dynamic list of dynamic lists, which have s that need to be POSTed to an MVC controller/action and bound as a typed object. The crux of my problem is I can't figure out how to manually pick out arbitrary POSTed form values in my…
BrianS
  • 51
  • 2
  • 6
3
votes
2 answers

Unable to parse Array Type Query string to List of Object

I am trying some paging and sorting stuffs in ASP.net core MVC 6 application. But when I pass array like query string MVC action unable to parse it to list. Query String looks like…
Sundar Singh
  • 654
  • 5
  • 15
3
votes
2 answers

Custom model binder - get post variables with same name?

I'm building a custom model binder in ASP.NET, and in my post variables I have couple of them with same name. Example: website.com?person=1&person=3&person=6 Currently I'm using request.Form.Get("name") syntax to get variables, but it returns…
Faruk Ljuca
  • 78
  • 1
  • 6
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…
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
3
votes
1 answer

Custom model binder for complex model with collection of polymorphic objects

How can I write custom model binder for complex model with collection of polymorphic objects? I have the next structure of models: public class CustomAttributeValueViewModel { public int? CustomAttributeValueId { get; set; } public int…
Neshta
  • 2,605
  • 2
  • 27
  • 45
3
votes
1 answer

Model Binding Custom Type

I have a struct which works much like the System.Nullable type: public struct SpecialProperty { public static implicit operator T(SpecialProperty value) { return value.Value; } public static implicit operator…
Paul
  • 6,188
  • 1
  • 41
  • 63
3
votes
1 answer

ASP.NET MVC2 - Resolve Parameter Attribute in Model Binder

Given an action like: public ActionResult DoStuff([CustomAttribute("foo")]string value) { // ... } Is there any way to resolve the instance of value's CustomAttribute within a ModelBinder? I was looking at the MVC sources and chances are I'm just…
Nathan Taylor
  • 24,423
  • 19
  • 99
  • 156
3
votes
1 answer

MVC Date Time Model Binding

I am using 2 kendo date pickers in my application as such:
Start Date:
@(Html.Kendo().DatePickerFor(m=>m.StartDate)) …
3
votes
1 answer

How to sanitize inputs before request validation enters in place in MVC 4?

I have my application and from the security testing team I got a bug reported about the possibility for a user to inject malicious code from our forms inputs. The application is developed in ASP.NET MVC4, .NET 4.5 and EF 5. The attack being tested…