model-binding

What's a good HTML naming convention for model binding complex nested types?

If I have an object that is composed of nested complex types, e.g. a ViewModel that has a List<Fu> and a List<Bar> public class WarViewModel { List<Fu> Fu { get; set; } List<Bar> Bar { get; set; } } public class Fu { public int Id {get;set;} public Soldier Private { get; set; } } public class Bar { public int Id {g...

Validation propagating to related objects

I have a model like this: public class Person { public int ID { get; set; } [Required(ErrorMessage="Name cant be empty")] public string Name { get; set; } public Person Friend { get; set; } } I want to create a new Person, and made a form with the fields using the strongly typed HtmlHelper ID Name Frien...

ASP.NET MVC2 -- Trouble with Model Binding and Html.Textbox()

ASP.NET MVC Model Binding is still new to me and I'm trying to understand exactly how it works. Right now, I appear to be having problems with a feature of Html.Textbox() Specifically, I have a View where I set Html.Textbox to a value both in the "Get" and the "Post". It sets fine in the "Get", but after the user submits a value during ...

How can I remove magic strings from custom model binders?

I've written a couple of custom model binders now, and have realised that I've fallen into the trap of relying on magic strings, e.g.: if (bindingContext.ValueProvider.ContainsPrefix("PaymentKey")) { paymentKey = bindingContext.ValueProvider.GetValue("PaymentKey").AttemptedValue; } I'd like to be able to use an exp...

ASP.NET MVC problem using image submit tag in Ajax.BeginForm

I'm developing a web app with ASP.NET MVC 2 (.NET 4.0), and I've run into a difficult problem. I've got the following code in a partial view: <% using (Ajax.BeginForm("CompleteTask", "Agenda", new AjaxOptions {HttpMethod = "POST"})) { %> <%: Html.EditorFor(x => x.Remarks) %> <%: Html.HiddenFor(x => x.TaskId) %> <%: Html.Hid...

ASP.NET MVC 2 Custom Model Binding Question

Background I have a payment page where the user can select from a list of existing payment methods, or specify a new one. The dropdown presents options such as: Visa - ******1234 (Saved) Mastercard - ******9876 (Saved) [New Credit Card ...] [New Electronic Check ...] Using jQuery, I toggle hidden DIVs that contain either an informa...

How ASP.NET MVC knows which property of JavaScript control to use when binding?

I know it's possible to change view representation of any .NET type by changing strongly-typed partial view. The most popular example is when simple ToString() call on DateTime instance is changed to a great-looking JQuery UI calendar. My question is - how does ASP.NET MVC know what property of JavaScript control to use when binding to a...

ASP.NET MVC 2 - Binding To Abstract Model

Hi Guys, If i have the following strongly-typed view: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<XXX.DomainModel.Core.Locations.Location>" %> Where Location is an abstract class. And i have the following Controller, which accepts a strongly-typed Model via a POST: [...

ASP.NET MVC 2: How to accomodate ValidationAntiForgery token AND use UpdateModel with posted JSON?

So I'm using ExtJs to post JSON for updates and creates to my ASP.NET MVC 2 application. I'm also using the ValidateAntiForgery attribute which only works when a POST is made. Question is: Can I use model binding in this scenario and if so, how? Here is an example of what the JSON looks like when I attempt to update a 'Company' entit...