Questions tagged [defaultmodelbinder]

For questions about .NET API DefaultModelBinder Class

defaultmodelbinder
Filter by
Sorted by
Tagged with
0 votes
0 answers
21 views

mode binder decimal to integer without commas

I have web api net framework 4.7 and I made a custom modelbinder that converts decimal numbers to integer. When they call my product post I have cases that come to me with 5.00. I want to take the ...
SCreativo's user avatar
1 vote
0 answers
239 views

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 ...
Gaz's user avatar
  • 11
0 votes
1 answer
693 views

Custom model binding using reflection in ASP.NET Core

I have the following Model public class MyModel { public string Name {get;set;} public int? Age {get;set;} public string City {get;set;} public decimal? Salary {get;set;} public JObject ...
LP13's user avatar
  • 32.4k
2 votes
1 answer
2k views

InvalidOperationException Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexTypeModelBinder.CreateModel(ModelBindingContext bindingContext)

I am trying to bind a complex type to a property to edit the property values and save the changes in memory, for now for testing. I get an exception when I execute Post. This is my Edit razor view. ...
Ahhzeee's user avatar
  • 123
2 votes
1 answer
337 views

GetUtcOffset returns the wrong off set for certain years / dates

var currentServerOffset = TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(1972, 03, 19, 02, 00, 00); using the above returns the wrong offset, but when you pass through 26th March it is corrected. ...
David Milloy Strachan's user avatar
0 votes
0 answers
75 views

I am getting exception on a post request logged in stackify but not able to find cause of the error

Following is the exception stackify shows me on dashboard: ERROR The string was not recognized as a valid DateTime. There is an unknown word starting at index 0. System.FormatException: The string ...
Pankaj Kaushik's user avatar
16 votes
2 answers
4k views

.NET core custom and default binding combined

I'm creating a custom model binder for a view model, implementing IModelBinder I have a lot of properties in my view model, the majority of which do not need any custom binding. Rather than ...
Dave0504's user avatar
  • 1,097
0 votes
0 answers
826 views

Add Controls Dynamically in ASP .NET Core

I've tried to follow the answer by Darin Dimitrov on this post: How to create controls dynamically in MVC 3 based on an XML file. But in ASP .NET Core (Specifically ASP .NET Core 2) there is no ...
Ivan Soriano's user avatar
0 votes
1 answer
48 views

How to bind properly with partial views w/o having to send in entire Model

I like to take sections of my view and break them out in to multiple partial views, and I like to only pass in the part of the model that partial view is interested in. Generally I like to put a model ...
BVernon's user avatar
  • 3,445
0 votes
0 answers
220 views

C# DefaultModelBinder does not bind property of type "dynamic"

I have been trying to figure this one out for the past 2 days... My main model contains a property of type "dynamic" and looks like this: public class WGTTestModel { private dynamic _oProp3 = ...
Tarek J.'s user avatar
0 votes
0 answers
478 views

Fluentvalidation with Custom Indexed Collection

Recently I've been working on a decently complex UI in which I've had to adjust the default collection binding to use a 1 based collection instead of 0 based which ends up with inputs like the ...
NOTACAT Studio's user avatar
6 votes
1 answer
2k views

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<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "...
Ramkumar Singh's user avatar
0 votes
1 answer
82 views

Found property which wasn't bound from response body (form data) to model MVC, default model binder

I send post request and get in response body form data: 0[family]=Marco&0[name]=Polo&0[age]=66&1[family]=Family&0[name]=Name&0[age]=22 var formData = "0[family]=Marco&0[...
Elena's user avatar
  • 135
1 vote
0 answers
84 views

Questions about Web API DefaultModelBinder Behaviour

Given, routes are set up like below For MVC : /entries/{entryID}/Children For API: /api/entries/{entryID}/Children The model I want the request to bind to is. public class Entry { public int ...
Kshitiz Shakya's user avatar
0 votes
3 answers
529 views

Setting a value before the submit doesn't send it to the controller

I have a view with multiples forms, each one submit should submit a hidden field with a specific value and all of the share the same model. From my controller I set the value before rendering the view,...
Heinrich's user avatar
  • 856
0 votes
4 answers
579 views

DateTime.Parse not working on an MVC custom binder

I'm getting a DateTime from an implicit binding at an Action in a .NET MVC web application. The problem is that i'm getting the date in format "MM/dd/yyyy" while i'm sending it through a query string ...
MorgoZ's user avatar
  • 2,032
2 votes
1 answer
2k views

Asp.net MVC Model binding derived class

I've written an abstract class PaymentMethod and 2 derived classes, PaymentMethodInvoice and PaymentMethodBilling. For each of them I've written shared EditorTemplates. The GET works fine, I select ...
mlauth's user avatar
  • 151
0 votes
2 answers
2k views

ASP.NET MVC5 Model Binder - Null when binding collection of collections

I have researched all over the net but hopefully here someone can help me. I have following ViewModel classes: public class PersonEditViewModel { public Person Person { get; set; } public ...
Rax's user avatar
  • 29
2 votes
1 answer
2k views

ModelState ErrorMessage Culture Localization

ModelState Validation Culture on HttpPost Error messages from ModelState not get localized I have read these questions and they didn't solve my problem. My problem: ModelState Validation ...
Sacmalama's user avatar
0 votes
1 answer
1k views

ASP.MVC 4 DefaultModelBinder fails on empty string binding to List

So if you post empty string to a controller like this <input type="text" value="" name="idList"> and try to bind it to a List very strange stuff occurs Does anybody faced this issue? Why it ...
Grebets Kostyantyn's user avatar
0 votes
1 answer
147 views

Using a custom DefaultModelBinder for MVC4 with interface does not populate additional properties

OK.. So I have an interface that I'm passing back to the controller when saving that looks kind of like this (removing most just to get the idea across). I can add more details if that is needed, but ...
user3720939's user avatar
1 vote
0 answers
271 views

Set a Parent property on Child Objects when binding

We have a hierarchical model of the shape (yuml-ized): And a controller action that takes an Order-typed parameter: public ActionResult UpdateOrder(Order order) { ... } With the posted form ...
chiccodoro's user avatar
  • 14.5k
0 votes
1 answer
190 views

What method or property should be overwritten in custom Model Binding?

I have a custom binding scenario for an MVC app that requires two pieces of functionality 1) A generic, reusable custom binder that allows mapping of form/query properties to class properties. 2) A ...
Jason's user avatar
  • 2,845
0 votes
1 answer
88 views

When is the DefaultModelBinder invoked within the ASP.NET Pipeline?

I want to know when the DefaultModelBinder is invoked within the ASP.NET Pipeline? Background: I want to find an approriate place where I can set the cultures of the current thread.
Rookian's user avatar
  • 20.1k
3 votes
1 answer
2k views

How to sanitize JSON input parameters when using MVC4 ApiController?

I had built an HTML sanitizer based on AntiXSS to automatically sanitize user input strings by overriding the default model binder, which works fine on standard post requests. However when using the ...
Michael Brown's user avatar
0 votes
1 answer
366 views

Submitting list of items with removed first one deletes all items

i have a model that has a list of sub items in it , something like this : class MyObj { public string Name {get;set;} public List<mySubObject> Items {get;set;} } and class ...
Nikola Sivkov's user avatar
1 vote
1 answer
1k views

How to set DefaultBinder ModelBinders.Binders.DefaultBinder in asp.net mvc 4 using autofac?

I want to set ModelBinders.Binders.DefaultBinder=new SmartBinder() in asp.net mvc 4 using autofac, what is the right way to do that?
user924691's user avatar
1 vote
1 answer
885 views

DefaultModelBinder Returning Subclass MVC4

I've been trying to read about this DefaultModelBinder for a couple of days now but I'm still very confused. I am using MVC 4 & EF 5 TablePerHiearchy structure. My problem is that I have a base ...
Fernando Marrero's user avatar
0 votes
0 answers
133 views

DefaultModelBinder code not getting called for MVC Remote Validation Calls

I have a DefaultModelBinder which I have inherited from and I have tried overriding the BindModel call and OnPropertyValidating call. However when using ASP.NET MVC's built in Remote validation, when ...
User101's user avatar
  • 798
1 vote
1 answer
386 views

HtmlAttributes dictionary not binding correctly

I have a model binding issue with an html helper I'm writing. I have declared a property on my Model to handle html attributes, In short; public IDictionary<string,object> HtmlAttributes { get; ...
Mark's user avatar
  • 404
4 votes
3 answers
3k views

Decoration on ViewModel property to use a different name for binding

On MVC3, is there a way to decorate a ViewModel property in order to get the DefaultModelBinder to use a different name for it in the request? For example, suppose you have the following view model: ...
Pablo Romeo's user avatar
  • 11.3k
0 votes
2 answers
2k views

How to tell the default model binder to ignore a property on postback

So I've this Fee abstract class in my Models (generated by EF with Database First in mind) public abstract partial class Fee { public int FeeId { get; set; } public int ProductId { get; ...
Simon Rapilly's user avatar
1 vote
1 answer
497 views

How to chain binders in asp.net MVC 4?

I just wrote my first model binder in asp.net MVC. I started with a pure HTML form that had all the inputs with names prefixed by "fm_". public class HuggiesModel { public string fm_firstname { ...
Aaron Anodide's user avatar
1 vote
2 answers
1k views

.NET MVC: how to get the model binder to assign null to a list property?

I have a model like so: class Model { public IList<Item> Items { get; set; } } class Item { public int Id { get; set; } } I am sending a request to an action method that takes a Model as ...
ChaseMedallion's user avatar
0 votes
1 answer
1k views

MVC view model with a list property that contains complex members

I have a model that looks like the following class ContainerClass { string Name { get; set;} Guid Id { get; set; } [UIHint("CustomSelectBox")] List<Member> Members { get; set; }...
WPFAbsoluteNewBie's user avatar
8 votes
1 answer
5k views

bindingContext.ModelName is empty?

So I'm trying to apply Darin Dimitrov's answer, but in my implementation bindingContext.ModelName is equal to "". Here's my viewmodel: public class UrunViewModel { public Urun Urun { get; set; } ...
Halo's user avatar
  • 1,522
0 votes
2 answers
112 views

Choosing object binder in action signature

I have a custom model binder to get data from session, but I also would like to use the default binder from time to time. Is it possible to choose model binder in action signature instead of using ...
Mariusz.W's user avatar
  • 1,367
3 votes
1 answer
4k views

How to return HTTP status code form Custom Model Binder

I have a custom model binder which pulls an implementation of an interface from a MEF container. It is implemented as follows: public class PetViewModelBinder : DefaultModelBinder { public object ...
psaxton's user avatar
  • 1,775
4 votes
1 answer
2k views

bindmodel vs createmodel asp mvc 3

I am developping my first application in Asp. I am using the environment Asp.NET MVC 3. I have a controller Action that has a single parameter. The type of this parameter is a complex object. public ...
minchiya's user avatar
  • 597
2 votes
3 answers
2k views

how to pass another parameter from jquery ajax to mvc controller, along with form.serialize()

I use a jQuery plugin called jscroller, which uses jquery.ajax to make ajax calls. I need to pass in all parameters from a search form, and deliver them to mvc controller, and I think the best way is ...
Tal l's user avatar
  • 265
2 votes
3 answers
3k views

MVC 3 empty query string parameter value is bound as an empty string rather than null

I have the following: This action: public virtual ActionResult Search(string search, string sort) { ... } Called from this url with empty query string parameters: http://myurl.com/mycontroller/...
tribus's user avatar
  • 1,110
2 votes
0 answers
387 views

Not getting resource file from DefaultModelBinder.ResourceClassKey

In my MVC3 project, in Global.Application_Start(), I have System.Web.Mvc.DefaultModelBinder.ResourceClassKey = "DefaultModelBinder"; I also have 2 resource files in App_GlobalResources: ...
getit's user avatar
  • 623
8 votes
3 answers
7k views

ASP.NET MVC 3 Validation on Nested Objects not working as expected - validates child object twice and not parent object

I am trying to get ASP.NET MVC 3 to generate forms from complex, nested objects. There is one validation behaviour I found which was unexpected and I am not sure if it's a bug in the ...
nootn's user avatar
  • 851
2 votes
1 answer
3k views

Custom Model Binder to bind nested property values

The reason I need this: In one of my controllers I want to bind all Decimal values in a different way than the rest of my application. I do not want to register a Model Binder in Global.asax (via ...
Attila Kun's user avatar
  • 2,275
1 vote
1 answer
1k views

DefaultModelBinder not binding model (always null) even though ModelState contains all required values

I am working with the sample ASP.NET MVC 3 application. I am working on a proof of concept for an API for a project I'm working on, by sending log in requests using HttpWebRequests. I am submitting ...
Dan Joseph's user avatar
12 votes
2 answers
19k views

bind attribute include and exclude property with complex type nested objects

Ok, this is weird. I cannot use BindAttribute's Include and Exclude properties with complex type nested objects on ASP.NET MVC. Here is what I did: Model: public class FooViewModel { public ...
tugberk's user avatar
  • 58.1k
5 votes
1 answer
5k views

Manipulate model value before passing it to DefaultModelBinder.BindModel

Some decimal and decimal? properties in my view model are marked as "Percent" data type, along with other data annotations, for example: [DataType("Percent")] [Display(Name = "Percent of foo ...
Dave Mateer's user avatar
  • 17.8k
1 vote
1 answer
712 views

MVC3 Form submit single input to Action with list parameter

I have a third party control that utilizes a single hidden input field to store a list of integers. This control is used throughout the site on numerous forms. The submitted value (as displayed in ...
mindlessgoods's user avatar
47 votes
6 answers
14k views

MVC3 Non-Sequential Indices and DefaultModelBinder

Is it true that the default model binder in MVC 3.0 is capable of handling non-sequential indices (for both simple and complex model types)? I've come across posts that suggest it should, however in ...
mindlessgoods's user avatar
6 votes
3 answers
954 views

Is there a reason why the default modelbinder doesn't bind to fields?

I'm using ASP.NET MVC3 and i'm wondering that the default modelbinder binds to public properties but not to public fields. Normally i just define the model classes with properties but sometimes i use ...
Jan's user avatar
  • 15.9k