model-binding

AutoMapper flattens Domain Models but does it do the opposite? If not, what does?

I've been reading up on AutoMapper because of a response to one of my earlier questions here. It says that AutoMapper flattens complex domain models, but I need something that does the opposite. I need to wire up my view models (flattened domain models) to the complex domain models so that I can quickly transform a view model into a doma...

Calling UpdateModel with a collection of complex data types reset all non-bound values?

I'm not sure if this is a bug in the DefaultModelBinder class or what. But UpdateModel usually doesn't change any values of the model except the ones it found a match for. Take a look at the following: [AcceptVerbs(HttpVerbs.Post)] public ViewResult Edit(List<int> Ids) { // Load list of persons from the database List<Person> peo...

How does a multiple select list work with model binding in ASP.NET MVC?

If you have a select list set to multiple in ASP.NET MVC, how does the modelbinding work? What does it return for your selected items, an array? <SELECT NAME="toppings" MULTIPLE SIZE=5> <option value="mushrooms">mushrooms</option> <option value="greenpeppers">green peppers</option> <option value="onions">onions</option> ...

ASP.NET MVC Model Binding Related Entities on Same Page

This problem has been driving me crazy for several hours now... In my domain, I have 2 entities that are related to each other Sku and Item. Each sku can have many items. public class Sku { private readonly EntitySet<Item> items; public Sku() { items = new EntitySet<Item>(AttachItems, DetachItems); } public...

Persisting the model binded object using Entity Framework

I'll try to keep this short and concise. I got my controller here... [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(CustomObject myCustomObject) { ... } Where myCustomObject looks great. But, if I want to save this using the entity framework, I need to do something like this... [AcceptVerbs(HttpVerbs.Post)] public Acti...

ASP.NET MVC Model Binder for Generic Type

Is it possible to create a model binder for a generic type? For example, if I have a type public class MyType<T> Is there any way to create a custom model binder that will work for any type of MyType? Thanks, Nathan ...

Model Binding an IList of selected items only

I have an action method setup: public ActionResult Delete(IList<Product> products) And a table of products in my view. I have got Model Binding working so that on submit I can populate the products list. But I would like to populate it with only the products that are selected via a checkbox. I think I could do it by changing the acti...

With MVC.NET Model Binding, does the view page Model and the binding Model have to be the same class?

(That is, the model that you pass to the view and the model that you get back once the form posts.) If not, is it better to do so anyways? What if there is data you are gathering that is beyond what the view page model has a property for? ...

ASP.NET Bind to IEnumerable

Hi, I'm passing a the type IEnumerable to my view, and for each item I output a html.textbox to enter the details into. When I post this back to my controller, the collection is empty and I can't see why. public class Item { public Order Order { get; set; } public string Title { get; set; } public doubl...

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 ...

If property or field is excluded when model-binding, what value will it have?

The question is in the title, actually - let's say I have a simple class like this: public class Product { public Int32 ID { get; set; } public String Name { get; set; } //... } When I use it in action method, like this: public ViewResult DoSomething([Bind(Exclude="ID")]Product product] { //... } what value will product.I...

ASP.NET MVC - Form Returns Null Model Unless Model is Wrapped in a Custom ViewModel

I have a pair of views in my application that both display the same Editor Template for one of my model items; of the two views ("Add" and "Edit"), "Edit" works fine, but "Add" is returning null for the model when my controller action handles the post. I found that if I give the "Add" view a custom ViewModel and call Html.EditorFor(p =>...

MVC Model Binding

I am using the MVC validation library from link text. I chose this library because I am also using .NetTiers which generates all of the Validation Attributes using MS Enterprise Library Validation Blocks. It works fine except that that model binding is automatically validating the object and populating the Validation summary. I believe...

Tinymce Model Binding with ASP.NET MVC

Hello, Does anyone know how to auto-populate the tinymce editor from the ASP.NET MVC model? In other words, what code do I need to use to set the contents of tinymce? EDITED: My problem is that tinyMCE is hiding my textbox contents. It opens blank, even though if I view the source of the page in my browser, it shows the correct info (i...

ASP.NET MVC: How to maintain TextBox State when your ViewModel is a Collection/List/IEnumerable

I am using ASP.NET MVC 2 Beta. I can create a wizard like workflow using Steven Sanderson's technique (in his book Pro ASP.NET MVC Framework) except using Session instead of hidden form fields to preserve the data across requests. I can go back and forth between pages and maintain the values in a TextBox without any issue when my model i...

asp.net image in a form and HTTPPost

HI, I'm sure I'm missing something very obvious here so please forgive me. I'm using MVC 2 Beta and I have a model that has several properties, strings, ints etc. the usual stuff. It also has a byte array that contains an image. I have an edit action method on my controller decorated with a [HTTPGet] attribute. The method passes the m...

Custom Binding in ASP.NET MVC with naming-conventions

Hey all I've got a View where I use a naming-convention on my text-fields, to indicate what should be done with the content once it is posted back to my controller. The format is similar to: <input type="text" name="RegistrationLine#ID" /> for updates <input type="text" name="CreateRegistrationLine#LineNumber" /> for create Now sinc...

Changing Model Binder per Controller instead of by type or with attributes?

I'd like to be able to swap model binders out on a per Controller or per ActionMethod basis. AFAIK the only options supported by the framework are to bind a model binder to a specific type. How could I change my model binder per Controller or per ActionMethod in a clean way? ...

Is this a bug in ASP.NET Model binding?

I have a simple form in ASP.NET MVC. I am trying to post these results to a controller action and I am getting strange behavior. The view is a simple HTML table: Here is part of the HTML form View: <form action="/Applications/UpdateSurvey" method="post"><table id=questionsTable class=questionsTable border=1> <thead><tr><td>Name</...

null values from listbox, are not evaluated in the model binding of ASP.NET-MVC

The model validation doesn't evaluates the attributes linked to listbox values if you don't select at least one of them. This way is not possible to do a model evaluation using DataAnnotations in order to inform required values. The controller: using System; using System.Collections.Generic; using System.Linq; using System.Web; using S...