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

Getting JSON from request body into a custom model binder with WebAPI

I've been implementing a custom model binder to handle the data returned from the datatables.net jQuery plugin but am having trouble actually getting to the data as it is being passed back in the request body and my ModelBindingContext only seems to…
Mourndark
  • 2,526
  • 5
  • 28
  • 52
3
votes
1 answer

ASP.NET Web API Operation with interfaces instead concrete class

My team needs to develop a framework for our company and products using this framework. One of the requisites is that a product could be customized for a specific client, yet it should be easily updated with another version of the same product (not…
3
votes
1 answer

Error implementing a Custom Model Binder in Asp.Net Web API

im stuck with this very strange problem. i have an API Controller named AttendanceController derived from APIControllerFA which is inturn derived from ApiController here is the code public class AttendanceController : ApiControllerFA { …
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
2
votes
1 answer

"An entity object cannot be referenced by multiple instances of IEntityChangeTracker" with a custom model binder

I've been following Darin's answer to a question I had on slimming down my controllers and I'm running into problems with this IEntityChangeTracker exception: An entity object cannot be referenced by multiple instances of…
John H
  • 14,422
  • 4
  • 41
  • 74
2
votes
0 answers

Bind Exclude not working Model Binding for child objects in ASP.Net MVC

I got into a issue in Model Binding in Asp.Net MVC. I have view model like below, public class ArticleViewModel : BaseViewModel { public Article art { get; set; } public List attachments { get; set; } …
Bala
  • 333
  • 1
  • 5
  • 13
2
votes
1 answer

How do I get MVC Model Binder to only bind non Null values for a list?

Following this question I was wondering if there is anyway to make MVC model binder only bind elements to a list if there is a value to populate them. For example if have a form with three inputs with the same name and one value isn't entered how do…
2
votes
0 answers

Custom model binder for form array data

I'm having trouble implementing a custom model binder that can bind custom "form fields" to correct array indexes. Here are my viewmodels: public class NewOrderViewModel { public Guid DeliveryAddressId { get; set; } public Guid…
mgajver
  • 21
  • 2
2
votes
2 answers

Custom Model Binder AspNet Core 2.2 for complex nested property

I have an Angular client and create a POST request with this body: {"Name":"example","Currency":"EUR"} I Use Odata protocol and my Controller is: [HttpPost, ODataRoute("Templates")] public IActionResult Insert([FromBody] Template value) …
2
votes
0 answers

Custom model binder does not work at nested property (ASP.NET Core MVC 2)

I'm trying to write a custom datetime model binder that is used to convert a posted string with format "dd/MM/yyyy" to a valid date on server (server date format is "MM/dd/yyyy". My source code looks like below: View Model TestViewModel.cs namespace…
TuanNA
  • 51
  • 2
2
votes
0 answers

Nullable DateTime Custom Model Binder

I have created a custom model binder to work with dates. I am having trouble working with nullable DateTimes. At present if the DataType of a ViewModel property is set to DataType.Data then the custom model binder is correctly called and produces…
G.James
  • 230
  • 1
  • 11
2
votes
1 answer

dot net core custom model binding for generic type parameters in mvc action methods

I am building a simple search, sort, page feature. I have attached the code below. Below are the usecases: My goal is to pass the "current filters" via each request to persist them particularly while sorting and paging. Instead of polluting my…
2
votes
1 answer

C# Web.API Cannot add custom model binder

I have API controller that has one Put method public class ScheduleExecutionsController : ApiController { public ScheduleExecutionsResponse Put([ModelBinder(typeof(TestBinder))]ScheduleExecutionsRequest requestInfo) { .... …
Vitalii
  • 10,091
  • 18
  • 83
  • 151
2
votes
2 answers

ASP.NET MVC - Custom Model Binder for ID fields

i have the following entities: public class Category { public virtual int CategoryID { get; set; } [Required(ErrorMessage = "Section is required")] public virtual Section Section { get; set; } [Required(ErrorMessage = "Category…
nfplee
  • 7,643
  • 12
  • 63
  • 124
2
votes
0 answers

Sharing a custom model binder between MVC 5 and Web Api

I'm hoping to get some advice about the best way to share a custom model-binder between MVC and WebAPI. The way I've done it, while functional, seems overly complex, and I'm fairly sure there must be a better way. I have a hybrid application that's…
2
votes
1 answer

DataAnnotations validation and custom model binder

I have an action method that accepts the following model - LanguagesViewModel: public class LanguagesViewModel : ViewModelBase { IEnumerable Languages { get; set; } } public class LanguageItem { [Required] public int LanguageId {…
Ant
  • 181
  • 2
  • 14