modelbinders

Nhibernate, MVC and ModelBinders

I want to configure my model binders with Nhibernate: So I have: <object id="GigModelBinder" type="App.ModelBinders.GigModelBinder, App.Web" singleton="false" > <property name="VenueManager" ref="VenueManager"/> <property name="ArtistManager" ref="ArtistManager"/> I have an attribute which marks controller actions so that they us...

ASP.NET MVC - Multiple models in a form and model binders

I have a form which needs to populate 2 models. Normally I use a ModelBinderAttribute on the forms post action i.e. [Authorize] [AcceptVerbs("POST")] public ActionResult Add([GigBinderAttribute]Gig gig, FormCollection formCollection) { ///Do stuff } In my form, the fields are named the same as the models pro...

Modelbinding database entities in ASPNET MVC

I'm having trouble trying to think what the best way is to recreate a database object in a controller Action. I want to make use of ModelBinders so in my action I have access to the object via a parameter, rather than having to repeat code to get an object from the database based on an identifier parameter. So I was thinking of having a...

Which Method of Model Binding Has Best Unit Test Semantics in ASP.NET MVC?

Definitions In ASP.NET MVC, there are two ways to do model binding in an action. Let's call these the "Bind arguments way" and the "UpdateModel way." Both of them do almost exactly the same thing, and they do it in almost exactly the same way: public ActionResult UpdateWithBindArguments(Foo model) { Repository.Update(mo...

Whitelist Model Binding doesn't seem to work with complex properties

I have a POST action that looks like this: public ActionResult Create([Bind(Include="userrole,credentials.emailAddress,credentials.password")]User u, string confirmPassword, bool agreeToTerms) I'm using the default model binder and credentials is a property on my User object. Credentials has two fields (emailAddress & password). If I ...

.Net mvc binders

Hello I'm having a disagreement with the model binders in Microsofts mvc framework. I have a base class for my domain models that have an id property that is readonly and type guid. But because it's readonly the binders can't set the value of the property. So am I totally screwed or can someone solve my problem? EDIT: Sorry as always t...

Optional property on a bound object in ASP.NET MVC

I'm trying to build a "New Customer" form, so I'm using the default model binder to build my Customer object: public ActionResult New(Customer customer) { ... } The only problem is I have a few properties on the Customer object that aren't required. When I leave these fields blank, ASP.NET MVC automatically throws up model errors stat...

ASP.NET MVC UpdateModel empty property

Given the following Model, public class A { public string Name { get; set; } } public class B { public string Address { get; set; } public A InstanceOfA { get; set; } } View, <%= Html.TextBox("A.Name") %> and Controller UpdateModel<B>(b, collection.ToValueProvider()); my b instance will contain a property of A with an empty ...

Registering ModelBinders

I have just updated to RC1 MVC from the beta product. I have the following code in my Application_start (in the global.ascx) System.Web.Mvc.ModelBinders.Binders[typeof(Shared.DO.Gig)] = new GigModelBinder(); This results in the following exception.... Method not found: 'System.Collections.Generic.IDictionary`2 System.Web.Mvc.ModelBin...

Model Binding within a Model Binder

Firstly, bear with me here. I have a custom model binder which is successfully mapping form data to a custom object. Within this model binder it also maps form items to different custom object. What I feel I should be able to do is create a separate model binder to take care of this second mapping. This is a simplified version. Custom o...

Intercepting action methods of an MVC controller

I use an O/R mapper, that can reload objects from the DB in a generic manner. I would like to be able to intercept the request right after the creation of the mapped objects, in order to reload them. ActionFilters are of course there, yet the problem is that ActionFilters (or the examples I have seen) can handle the data as provided by...

Custom Model Binder for Complex composite objects HELP

Hello Everyone, I am trying to write a custom model binder but I'm having great difficulty trying to figure how to bind complex composite objects. this is the class I'm trying to bind to: public class Fund { public int Id { get; set; } public string Name { get; set; } public List<FundAllocation> FundAllocations...

Validating with a Service Layer

I have followed the the article on asp.net.mvc, Validating with a Service Layer. This all works fine until I come against a custom ModelBinder. If a form item fails validation within my Service Layer, I update my Validation Dictionary (which is the ModelState passed in by the calling Controller) and all is well. When the Controller passe...

Where is the documentation for the standard ASP.NET MVC ModelBinder?

I don't seem to be able to find any authoritative, up-to-date (i.e. for 1.0 final) documentation for the capabilities of the standard model-binder in ASP.NET MVC, particularly with respect to binding complex objects involving collections (and the naming requirements this places on the HTML form) I have found a blog post from Phil Haack ...

Modelbinding lists

I got a controller action like public class Question { public int Id { get;set; } public string Question { get;set; } public string Answer { get;set; } } public ActionResult Questions() { return View(GetQuestions()); } public ActionResult SaveAnswers(List<Question> answers) { ... } the view> looks like: <%...

Is it possible to accept a List<Guid> as a paramater from checkboxes in Asp.Net MVC?

I know its possible to accept a list of objects as a parameter thanks to haacked but what about a list of Guids from checkboxes? This is a bit different as the only name you get has to be the ID. Any help would be greatly appreciated, thanks! ...

ASP.NET MVC posted file model binding when parameter is Model

Is there any way to get posted files (<input type="file" />) to take part in model binding in ASP.NET MVC without manually looking at the request context in a custom model binder, and without creating a separate action method which only takes a posted file as input? I would have thought that this would work: class MyModel { public Ht...

ASP.NET MVC - Mixing Custom and Default Model Binding

Hello, I have a type: public class IssueForm { Order Order {get; set;} Item Item {get; set;} Range Range {get; set;} } I created a custom model binder due to requirements on Order and Item, but Range could still use the Default Model Binder. Is there a way from within my custom model binder to call the default model bind...

Bind a routevalue to a property of an object that is part of viewmodel

I have the following route: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); and I...

ASP.NET MVC: avoid tight coupling when binding form POST to parameter

Let's say I have an interface like: interface IThing { int Id { get; set; } string Title { get; set; } } And in ASP.NET MVC I have a form that posts to a controller action like this: [AcceptVerbs(HttpVerbs.Post)] public ActionResult NewThing([Bind(Exclude = "Id")] SimpleThing thing) { // code to validate and persist the...