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
1
vote
0 answers

ASP.Net MVC model binding child list property

I have a controller action method [HttpPost] public ActionResult Create(MyItem item){ ... } My type definitions look like this public class MyItem{ ... public List MySubItems{ get; set; } } public class MySubItem{ …
Jimbo
  • 22,379
  • 42
  • 117
  • 159
1
vote
0 answers

Custom Model Binder to Override BindProperty

Morning/Afternoon/Evening all, I'm pretty new to working within model binders and creating a custom model binder, so some things wont be clear to me. I'm attempting to create a custom model binder in order to validate/review each string property…
Gaz
  • 11
  • 2
1
vote
1 answer

Not getting my service injected in Model Binder Provider

Is there any reason why I'm not getting an injected service into my custom RegisterBinderProvider? services.AddScoped(); services.AddMvc(options => { …
1
vote
1 answer

How to make a custom ModelBinder automatically apply to all properties of a certain type

EDIT: So it turns out that my ModelBinder isn't actually the problem. The issue is with my ValueConverter. Leaving this here, as I think it illustrates how to do a custom model binder though. There is a lot of code in this question. I'm trying to…
Nic Estrada
  • 480
  • 5
  • 16
1
vote
0 answers

Dynamic parameters in controller ASP.NET MVC C#

I'm sending a json in the view with an ajax request and need to use it in the controller. But this json has dynamic parameters that means somethings it could have 10 or more properties so I cannot define a model. How can I get access to the…
bat man
  • 33
  • 4
1
vote
1 answer

How to make a custom string object modelbind in MVC?

I created a custom string object, but it does not modelbind when I post it back to the server. Is there an attribute I'm missing on the class or something? This is the custom string class below: public class EMailAddress { private string…
1
vote
1 answer

Why default Model binder behaving differently?

I am creating API in which has following url /api/abc/?q=1&a=2&b=3&b=4 ^^^^^^^ Input.cs(class used in ModelBinding) ... public string A { get; set; } public string B { get; set; } public string Q { get; set; } ... I am using…
yajiv
  • 2,901
  • 2
  • 15
  • 25
1
vote
0 answers

How to trim spaces of model in ASP.NET Web API using ModelBinder

I can able to find lot of related answers to trim extra spaces in model input in ASP.NET MVC API. Referred below links, How to trim spaces of model in ASP.NET MVC Web API Best way to trim strings after data entry. Should I create a custom model…
Magendran V
  • 1,411
  • 3
  • 19
  • 33
1
vote
1 answer

DateTime custom Model Binder for database multilanguage routing

I have an application with a custom database routing: routes.Add("RouteWeb", new RouteWeb()); public override RouteData GetRouteData(HttpContextBase httpContext) { if (httpContext.Request.IsAjaxRequest() || httpContext.Request.Url == null)…
1
vote
1 answer

Asp.net MVC Custom Model Binder for decimals - adds model error when decimal action param is null

I've created a custom model binder based on an article from Haacked. Here's the code: namespace MyNamespace.Project.ModelBinders { public class DecimalModelBinder : DefaultModelBinder { public override object…
Jacques
  • 6,936
  • 8
  • 43
  • 102
1
vote
1 answer

Custom Model Binder In Asp.Net Core for Sub Classes

I have a scenario where I have a certain base class we will call it "PagingCriteriaBase" public class PagingCriteriaBase : CriteriaBase { public Int32 CountOfItemsPerPage { get; set; } public SortOrder SortingOrder { get; set; } public…
1
vote
1 answer

C# ASP.NET Core ModelBinder not Updating Model

I have created a ModelBinder, which only gets triggered if an object has a [Decimal] attribute assigned, yet for some reason, despite it actually sanitising the data it does not seem to update the posted model. I wonder if someone could see from my…
iggyweb
  • 2,373
  • 12
  • 47
  • 77
1
vote
3 answers

Issue when assigning values to Custom Model Binder

I am getting An exception of type 'System.NullReferenceException' occurred in *****Tests.dll but was not handled in user code Additional information: Object reference not set to an instance of an object. How to correctly assign values to the…
Harsha W
  • 3,162
  • 5
  • 43
  • 77
1
vote
0 answers

Custom model binder returns empty object with correct structure

I'm trying to create model object using custom binder: public class AccidentProtocolStep4ModelBinder : DefaultModelBinder { protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, …
1
vote
3 answers

Custom Model Binder - How to revalidate

I'm using ASP.NET MVC 2 and want to figure out how to re-trigger the validation on my model after it has been populated using a custom binder. So, I start with a couple of EF classes which are associated, Booking and Traveller (each booking can have…
Brendan
  • 1,033
  • 10
  • 12