modelbinders

I need a DataAnnotationsModelBinder for DataAnnotations v 3.5

I need a DataAnnotationsModelBinder that is going to work with System.ComponentModel.DataAnnotations v 3.5 i have found one on codeplex, but is for the v 0.99 of DataAnnotations and it doesn't work with v 3.5, and my xVal doesn't work with DataAnnotations v 0.99, so i'm kinda stuck ...

Overriding updatecollection in defaultmodelbinder

I'm having a problem with the default model binder creating new entities when I bind a entity with child collection rather than updating the existing child entities. I found what looks like a good solution in this post link text but I don't want to have to change the mvc source. Can someone tell me how I could override this method in...

MVC Views and Controllers: Re-instantiate entities when form submitted

We are working with entities in our MVC controllers which are passed to strongly typed views. How do we re-instantiate these entities in the controller with updated data when the form is posted in the view? The form does not contain all the fields of the entity so all of the data needed to re-instantiate the entities won't be there in ...

Testing Model binding in ASP.NET MVC 2

First; I know that I should not need to test the internals of MVC but I REALLY need a suite a tests around data flowing into our system. How can I, I hope without mocking all of HTTP context, test that objectA (form collection, dict, collection, object, etc) does or does not conform to objectAModel? I'd like to not have to instantiate...

ASP.NET MVC ModelBinding Inherited Classes

I've got a question about ModelBinding in ASP.NET MVC (I'm using MVC 2 preview 2) related to inheritance. Say I have the following interfaces/classes: interface IBase class Base : IBase interface IChild class Child: Base, IChild And I have a custom model binder BaseModelBinder. The following work fine: ModelBinders.Binders[typeof(C...

ASP.NET MVC 1: DataSet ModelBinding

I'm in a situation where I'm being given a dataset to output to an MVC view. I'm really struggling to figure out how to get the modelbinder to pick it up on the way back in after a submit. I have something like this... public ActionResult TestData() { DataSet data = new DataSet("DS"); DataTable table = new DataTable("DT"); ...

Asp.Net MVC 2 Beta ModelBinder Change

I am trying to modify the following custom model binder according to the ValueProvider breaking changes in MVC 2 Beta. protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext) { var obj = bindingContext.Model as Core.BusinessBase; if (obj != null) { var...

Asp.net MVC accept formatted input?

How is formatted user input typically handled in an MVC application? A user entering "1,000.00" for a number for example. I'm somewhat surprised the default ModelBinder does not pick up on this. Would this be the type of thing I would create my own ModelBinder for? ...

Getting SelectedValue back from a DropDown in ASP.NET MVC (C#) using Entity Framework

Sorry if this is a repeated question, I scanned the related questions and didn't see anything obvious. I'm using an EditModel with an Entity object, along with two SelectLists in it. The problem is, once I reach my POST action, the SelectedValues for both drop downs are still the same default values I set in the constructor for the mode...

Where to catch exceptions from customized ModelBinder

Hi all, I have a customized ModelBinder which bind web from with a object using code like this" [ModelBinder(typeof(CustomizedModelBinder))] public class Widget{ ... } This modelbinder may throw exceptions and where should I add code to catch those exceptions? Thanks in advance! ...

ASP.NET MVC 2 - Setting values on IValueProvider

I am attempting to upgrade my MVC 1 project to MVC 2 RC. We currently have a custom modelbinder that adds items to the ValueProvider (this worked when it was a dictionary). We then passed this off to the default modelbinder. However, IValueProvider does not have an add method, so this algorithm no longer works. Does anyone know of a way ...

Model Binding With Entity Framework (ASP.NET MVC)

Earlier I created an AddClient page that (when posted) passed a client object and I used db.AddToClient(obj) in my repository to persist it. Easy stuff. Now, I have a details page whose save submits a post to an action "UpdateClient". Before that action is hit, my custom model binder creates my Client object and it's conveniently hand...

mvc.net DateTime with Time part in URI

I have a set of actions that are returning time-series data with-in ranges specifiable to the minute. They work fine with querystrings, i.e. /mycontroller/myaction?from=20091201 10:31&to=20091202 10:34 with or without URL encoded colons, but I thought it would be nice to have a pretty URL /mycontroller/myaction/from-20091201 10:31/to-2...

Can't add ModelBinder attribute to a property of input model

I want to specify the model binder to use for a property of my input model. public class SendEmailInput { [Required, EmailAddress] public string From { get; set; } [Required] public string To { get; set; } [Required] public string Subject { get; set; } [Required, ModelBinder(typeof(RadEditorModelBinder))] ...

Unit testing custom model binder in ASP.NET MVC 2

I've wrote custom model binder in project, that uses ASP.NET MVC 2. This model binder bind just 2 fields of model: public class TaskFormBinder : DefaultModelBinder { protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) ...

asp.net mvc strongly typed view model with multiselect

Hi, I would like to know how i can bind my form values to my strongly typed view from a MultiSelect box. Obviously when the form submits the multi-select box will submit a delittemered string of my values selected...what is the best way to convert this string of values back into a list of objects to attach to my model to be updated? p...

Binding ViewModels With Other ViewModelBinders

I have a viewmodel (lets call it HouseVM) but it contains another viewmodel inside of it (KitchenVM). I've already created a custom model binder for KitchenVM. Now I'm creating the HouseVM modelbinder. How can I access the model binding I've already done for KitchenVM within the HouseVM model binder? NOTE: I have seen this post ...

ASP.NET MVC: Multiple model binding

Hi, is it possible to use some kind of Multibinders, like this? [Authorize] [AcceptVerbs("POST")] public ActionResult Edit([CustomBinder]MyObject obj) { ///Do sth. } When i ALSO have configured a default binder like this: protected void Application_Start() { log4net.Config.XmlConfigurator.Configure(); Regi...

How can i use a ModelBinder to correct values that will then be visible to the user?

I want to write a modelbinder for ASP.NET MVC that will correct values that will be visible to the user. Maybe it will capitalize the initial letter of a value, trim strings, etc. etc. I'd like to encapsulate this behavior within a modelbinder. For instance here is a TrimModelBinder to trim strings. (taken from here) public class Tri...

asp.net mvc: TryUpdateModel return value or ModelState.IsValid?

Doing validation in my binder, I'm wondering if there's a need to check the return value. In Option 1 below, is there ever going to be a difference in case 1 and case 2? It doesn't seem possible that TryUpdateModel would return true, but ModelState.IsValid is false. Option 1: if (TryUpdateModel(editItem, new string[] { "Field" })) ...