modelbinding

Action with set of fixed parameters in url and a set of optional parameters either from post or from querystring

In my route collection I have routes.MapRoute( "Recalculate", "{siteLanguage}/Formula.mvc/relcalculate/{identifierString}/{formulaId}/{wratio}/{customRecalcString}", new { controller = "Formula", action = "Recalculate", wratio = "", customRecalcString = "" } ); The action it maps to is public ActionResult Recalculate(string ide...

ASP.NET MVC Updating a list of objects on one form? (model binding to a list)

Hello (again) Quick question regarding updating a list of items in asp.net mvc. Basically I have an edit action method that returns a collection of objects (incidentally, the table structure of which looks as follows 'testID, assetID, Result' - a link table). I basically want this items to be displayed one after another in a form and ...

Unit test a controller with custom model binder

In my application I have a custom model binder that I set to the DefaultBinder in the global.asax: ModelBinders.Binders.DefaultBinder = new XLDataAnnotationsModelBinder(); When writing unit tests for controllers I need to make sure the controller uses the custom model binder but I don't know how to do this. My test looks like this: ...

Exception Causes ModelBinding To Fail

If I receive a generic error in my ASP.NET MVC 2.0 Beta app and catch it. I notice that the next time I post that the model returned to my post is always null. Do I need to clear out the ModelState error or something? ...

ViewModel approach interferes with ModelBinding in MVC 2 when using the new "For" HTML helpers

I am using .net MVC 2.0 and have set up an edit view that receives a custom ViewModel object. The ViewModel is a class with two properties: // Properties public Portfolio Portfolio { get; private set; } public SelectList slSectors { get; private set; } In my view there is a form with the purpose of updating the Portfolio Object. The...

ASP.NET Collection Model Binding Nested Form Problem

I have a partial view that is bound to an object Cart. Cart has a collection of CartLines. My view is below: <tbody> <% foreach (var line in Model.Lines) { %> <tr> <td align="center"><%=Html.CatalogImage(line.Product.DefaultImage, 80) %></td> <td align="left"> <%=Html.Actio...

ASP.NET MVC 2 UI Templates displaying data without markup. How to fix?

Using EditorFor( model lamda, "viewTemplateName"), my output is completely not as expected. This doesn't produce any errors, but it is rendering output without markup. What am I doing wrong? The Output: HarryTomRichard The Expected Output (I need to figure out how to render the List [] indexes on id too but not to that problem ye...

Binding HttpPostedFileBase using Ajax.BeginForm

Hi, I have a form which binds a model and a file upload using the default binder for HttpPostedFileBase. This works fine when using Html.BeginForm(). However, I wanted to perform the same action using AJAX so I replaced this with Ajax.BeginForm() changing the parameters accordingly. The model still binds correctly, however I can't get...

Modelbinding Failing VS2010 asp.net mvc2

The contactAddModel.Search always comes through as null - any ideas? View declaration <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<rs30UserWeb.Models.StatusIndexModel>" %> ViewModels public class StatusIndexModel { public ContactAddModel contactAddModel; public...

MVC 2, IoC, ModelView, and Binding ...

If you can register your Controllers in your IoC implementation then why can't you also have your ModelViews created from your IoC container? I'm currently using Autofac 1.4 for IoC injection for the controllers with the following: ControllerBuilder.Current.SetControllerFactory((IControllerFactory) new AutofacControllerFactory(Contain...

Asp.net MVC - Model binding image button

I've got a very complex form and i'm using the MVC model binding to capture all the information I've got it set up to capture all the different submissions that can happen as there are about 10 different submit buttons on the form, and there are also 2 image buttons I tried to get a bit clever (or so i thought) with capturing the image...

ASP.Net MVC 2 - ModelBinding and Dictionary<int, int>

Hi, In my interface I have a list of text boxes, something like this : http://screencast.com/t/YjIxNjUyNmU The number of textboxes is unknown as each of them is associated with a Template. In my page, the goal is to associate a number to some of those templates. Here is a sample HTML code : <% // loop on the templates foreach(IT...

ASP.net MVC Linq-To-SQL Many-To-Many Field Binding

Possible Duplicate: Modeling a many-to-many relationship in ASP.NET MVC using LINQ to SQL Hi there, The short version of this question is "Is there a way to gracefully handle database insertion for an object that has a many-to-many field that has been set up in a partial class?" Apologies if it's been asked before. Example S...

Asp.Net MVC 2: How exactly does a view model bind back to the model upon post back?

Sorry for the length, but a picture is worth 1000 words: In ASP.NET MVC 2, the input form field "name" attribute must contain exactly the syntax below that you would use to reference the object in C# in order to bind it back to the object upon post back. That said, if you have an object like the following where it contains multiple Ord...

Mvc2 dropdown list returning val as string, want to change the type.

So I have some drop down lists in a view (apologies for the wall of code, thought it better to post to much than not enough): //...blah... <%=Html.DisplayFor(m=>m.PlanType.PlanTypeType) %> <%=Html.DisplayFor(m=>m.YearLevel.YearLevelName) %> <%=Html.DisplayFor(m=>m.Subject.Subject1) %> //..moreblah... rendered via an editor...

How to handle nested models in ASP.NET MVC

Hi all, I have been looking around for a nice working solution on how to correctly handle model binding with nested attributes. I have one model that has a list of other child models like below: public class Organization : IEntity { [ScaffoldColumn(false)] public int ID { get; set; } [LocalizedDisp...

Why are my checkboxes not binding to my View Model?

I have a view model for a business. This model conatains a view model for address, contact details and also an IEnumerable. I use editor templates to display the checkboxes. The problem is when I'm on the edit action and post the form the categories come back as null. I have read a few similar questions but havent found a solution that ...

This modelbinding from jquery, what's wrong with it?

I have the following action: public JsonResult GetGridCell(double longitude, double latitude) { var cell = new GridCellViewModel { X = (int)Math.Round(longitude.Value, 0), Y = (int)Math.Round(latitude.Value, 0) }; return Json(cell); } I'm calling it with the following jquery: $.post('Grid/GetGridCell', { longitud...

CultureInfo issue with Modelbinding double in asp.net-mvc(2)

In my Jquery script I post two doubles using the browser's CultureInfo (en-UK) that uses the .as a fraction separator. My MVC app is running on a server with locale nl-BE using the , as a fraction separator. [AcceptVerbs(HttpVerbs.Post)] public JsonResult GetGridCell(double longitude, double latitude) { var cell = new GridCellViewMo...

ASP.NET MVC - Cleaning Up URLS in Complex Model Binding Scenarios

In one of the applications I am building I have constructed a very flexible attribute-based system for describing products in my database wherein each product can have an indeterminate number of attributes assigned to it with each attribute having a single "type". So, for example, one attribute type might be "Category" and the value assi...