modelbinders

ASP.NET MVC - Binding a Child Entity to the Model

This one seems painfully obvious to me, but for some reason I can't get it working the way I want it to. Perhaps it isn't possible the way I am doing it, but that seems unlikely. This question may be somewhat related: http://stackoverflow.com/questions/1274855/asp-net-mvc-model-binding-related-entities-on-same-page. I have an EditorTemp...

ASP.NET MVC - Custom Model Binder on Interface Type

I'm not sure if this behavior is expected or not, but it seems that custom model binding doesn't work when the binding is assigned to an interface type. Has anyone experimented with this? public interface ISomeModel {} public class SomeModel : ISomeModel {} public class MvcApplication : HttpApplication { protected void Application_...

Can I use MVC validation attributes within a custom model binder?

I have lots of MVC validation attributes on my model. Everything works great when the defaultModelBinder binds my model on submit. But, I need to create a custom modelbinder. I'd like to continue using my validation attributes. Can I? If so, how? ...

MVC 2, Custom ModelBinder, and storing the "attempted value" for the view

I have an object that was previously round-tripping from the server to the client and back nicely (i.e. edit and view forms worked fine). However, I've added to that object a complex type and made a custom ModelBinder to handle it. The complex type can be represented as a single string but is stored in the object as a Decimal (think "0...

ASP.NET MVC Model Binding into a List

In my ASP.NET MVC site, part of a feature allows the user to enter the hours when a certain venue is open. I've decided to store these hours in a VenueHours table in my database, with a FK-to-PK relationship to a Venues table, as well as DayOfWeek, OpeningTime, and ClosingTime parameters. In my View, I want to allow the user to only in...

ASP.NET MVC: null reference exception using HtmlHelper.TextBox and custom model binder

I have written a class which implements IModelBinder (see below). This class handles a form which has 3 inputs each representing parts of a date value (day, month, year). I have also written a corresponding HtmlHelper extension method to print out three fields on the form. When the day, month, year inputs are given values which can be p...

.NET MVC 2.0 Custom Model Binder not called when using SWFUpload

I am uploading files using SWFUpload. To get the data I need passed along with the file, I am adding post params to swfupload. The problem is that the custom model binder I have written is not called when the controller method is called by swfupload. Some of the properties of my model are set, but not the properties controlled by my c...

Creating a DropDownList from database entries and then binding it in form submission

I have entries for an enumeration stored inside a database table with only the following fields: ID and Name. I want to show the values stored inside this table inside a DropDownList on a form. The user then chooses a value and submits the form. I found a way to easily create a DropDownList from an enumeration (although it would probabl...

How do I invoke UpdateModel from within a Custom ModelBinder? (MVC)

Hi, 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 to the standard ModelBinder routing. How do I do this? For illustration purposes I'...

Where to put ParseUrl() or similar function that works against a datastore, in ASP.NET MVC?

If you were to code a function/method that would, for entered string or slug (for instance in Create or Edit view), go into datastore and check whether that string or slug exists and in this case create a link to it, where would you put it? For instance, we have a "Link" textbox on our Create or Edit form. I have a jQuery autocomplete w...

ASP.NET MVC Model Binder not working with a dictionary

Hi, Given the following view model and action using the DefaultModelBinder, it seems to ignore the dictionary, but bind all other properties correctly. Am I missing something here? Looking at the MVC source code this seems legit. Thanks public class SomeViewModel { public SomeViewModel() { SomeDictionary = new Dictiona...

ModelState reported as invalid for private properties on a model in ASP.NET MVC 2

I'm using ASP.NET MVC 2.0 and I am trying to take advantage of the model binding in my controller and also the modelstate validation. However I have come up against a problem and wanted to share it with people on here to see what you think. Ok I have my clean User poco in my model class library... namespace Model { public part...

How to prevent validation of relationships in model binder?

An example, if I have a class named Order with a field referencing a Customer, and then an Order form with an drop down list (<%= Html.DropDownListFor(e => e.Customer.ID, new SelectList(...)) %>) for setting the Customer the model binder will create an empty Customer with only the ID set. This works fine with NHibernate but when validati...

Model Validation with dictionary

Hi, Say I have a model like so: public class MyViewModel { //some properties public string MyString {get;set;} public Dictionary<string,string> CustomProperties {get;set;} } And I am presenting the dictionary property like this: <%= Html.EditorFor(m => m.CustomProperties["someproperty"]) %> All is working well, however I hav...

asp.net mvc 2 - Model Binding and Select Lists

I have the following select list: <select d="Owner_Id" name="Owner.Id"> <option value="">[Select Owner]</option> <option value="1">Owner 1</option> <option value="2">Owner 2</option> <option value="3">Owner 3</option> </select> It gets bound to: public class Part { // ...other part properties... public Owner O...

Input file autobind to byte[] aray in ASP.NET MVC

Anyone managed to get default binder to work with input file control and property of type byte array? If I have a property on my ViewModel named Image and a file input control on my view name Image, default binder issue this error: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding cha...

Will the Sharp Architecture ModelBinder properly constitute an object using a jQuery ajax request?

Do you know if it's possible to make an AJAX request and have the model binder properly constitute an object based on the parameter provided? For example: $.ajax({ type: 'POST', url: '../Create', data: ( { 'SkillTypeRequest.Id': 0, 'SkillTypeRequest.Event.Id': eventId, 'SkillTyp...

Getting the Action during model binding

Hi, Is there a way of getting the Action, and reading any attributes, during the model binding phase? The scenario is this: I've got a default model binder set-up for a certain data-type, but depending on how it's being used (which is controlled via an attribute on the action) I need to ignore a set of data. I can use the RouteData o...

MVC custom model binder issue

Hi, I have a textbox in my view that i want to receive the value as a List of strings. As example, if anybody enters: tag1,tag2,tag3... receive a List with 3 elements. I did a custom model binder, but im still receiving from the post the string instead the List. This is the stuff that i did: This is my Model: public class BaseItem...

ASP.Net MVC ModelBindingContext class-- how are its model values populated?

I'm scratching my head a bit at how model binders do their work in ASP.Net MVC. To be specific, the BindModel() method has a ModelBindingContext parameter that holds the model name and type, but I don't understand how the ModelBindingContext receives these values. An MVC model has to be populated from posted form values or query st...