model-binding

Hydrating ViewModels in ASP.NET MVC

I have a page that is made up of many user controls. The view model for this page is rather complex. public class ComplexViewModel { public ObjectA ObjectAProperty { get; set; } public List<Things> ListOfThings { get; set; } public List<ThingCategories> ListOfThingCategories { get; set; } public List<ThingTypes> ListOfT...

ASP.Net MVC : Sending JSON to Controller

I want to be able to send JSON as opposed to the standard QueryStrings when making a post to my controllers in ASP.Net MVC. I have the Front-End stuff working fine (building and then submitting my JSON objects). The problem is on the controller side where the default ModelBinders that ship with the MVC framework do not support this. I...

MVC2 IModelBinder and parsing a string to an object - How do I do it?

I have an object called Time public class Time{ public int Hour {get;set;} public int Minute {get;set;} public static Time Parse(string timeString){ //reads the ToString()'s previous output and returns a Time object } override protected string ToString(){ //puts out something like 14:50 (as in 2:50PM) } }...

Model-binding an object from the repository by several keys

Suppose the following route: {region}/{storehouse}/{controller}/{action} These two parameters region and storehouse altogether identify a single entity - a Storehouse. Thus, a bunch of controllers are being called in the context of some storehouse. And I'd like to write actions like this: public ActionResult SomeAction(Storehouse sto...

Custom Model-Binder that pulls from a cookie problem?

I am trying to do the following. Use the default model binder to bind an object from query string values. If that fails, I then try and bind the object from cookie values. However I am using dataannotations on this object and I am having the following problems. If there are no querystring parameters the default model binder doesn't...

When my View POSTs a Model back to my Action, how do I save it back to the database it came from?

I'm kind of confused... I have one action that takes an ID, loads up an object, and passes it to the View which is bound to the Model of that object's type. After editing the data in the form supplied by the View, I POST back to another action that accepts an object of the same exact type as the Model. However at this point I can't ju...

how to retrive value from textbox in asp.net mvc2

I am working on chart project in asp.net mvc so any one can kindly tell me how to retrive values from the text boxes to apply to the series of the chart? ...

ASP.NET MVC 2.0 - IList<T> CheckBoxes

What is the best way to handle this: class Option { int id; string name; } class QuoteItem { IList<Option> options; } class QuoteViewModel { IList<Option> allOptions; QuoteItem quoteItem; } Basically, I have all the available options in allOptions. I want to have a checkbox that puts another Option (even if it...

Modifying type-specific properties in implementation of interface

I know this is a silly question, in that the answer is likely an "oh right, of course!" one. Here is what I have: public interface IEvent { int Id string Title } public class MeetingEvent : IEvent { int Id string Title //Meeting Properties string Room; User Organizer; } public class BirthdayEvent : IEvent { int Id ...

Model Binding to Multiple Types with Same Property Names

Hi All I have a view that contains 2 list boxes: Audience & Locale I'm trying to submit a form that contains the selected index of both to my controller, which has an action method of this signature: public JsonResult Submit(Audience aud, Locale loc) { // do stuff } The problem I'm having is both Audience & Locale have an ID propert...

Model Binding is Failing when I pass JSON via $.get().

This question is related to the this. I'm using the following to extract the attributes & values from the select elements on my page: var valuesArray = $("select").map(function() { return $.getAttributes($(this).find(":selected")); }); var arr = new Array(); $.each(valuesArray, function() { arr.push($(this)[0]); // this filter...

Asp.net MVC Form Post to Action with missing parameter initialization

I am having trouble with an ASP.net MVC form Posting to an Action containing multiple parameters. The problem is only some of the parameters are being initialized. The page has multiple forms each backed by a separate controller. The controller action receiving the Post action looks like this public ActionResult Create(int institution...

Model binding postback data to a controller action parameter of type List<T>

I have a strong type view of type List<List<MyViewModelClass>> The outer list will always have two lists of List<MyViewModelClass>. For each of the two outer lists I want to display a group of checkboxes. Each set can have an arbitrary number of choices. My view model class looks similar to this: public class MyViewModelClass { ...

Model Bind to a List<> when Posting JavaScript Data Object

Hi Guys I'm trying to post a JavaScript data object with the following: $.post(frm.attr("action"), data, function(res) { // do some stuff }, "json"); where 'data' takes the structure of data - panelId - siteId - ConfiguredFactsheetId // this is an array of CheckBox ids that correspond to ConfiguredFactsheets - 123 - 234...

Model binding with nested child models and PartialViews in ASP.NET MVC

I have the following types and classes: { namespace MVC.Models public class Page { public EditableContent Content {get; set; } } public class EditableContent { public TemplateSection SidebarLeft {get; set; } public TemplateSection SidebarRight {get; set; } } } I want to edit...

ModelBinding to an EntitySet (MVC2 & LinqToSQL)

Hi all There seems to be an issue with the default model binder when binding to an EntitySet causes the EntitySet to be empty. The problem is described here and here: Microsoft's response is: ... We have now fixed this and the fix will be included in .NET Framework 4.0. With the new behavior, if the EntitySet passed into Assign is t...

ASP.NET Model Binder and base type

My model inherits from an interface: public interface IGrid { ISearchExpression Search { get; set; } . . } public interface ISearchExpression { IRelationPredicateBucket Get(); } The model: public class Project : IGrid { public ISearchExpression Search { get; set; } public Project() { t...

Linq2Sql loading associated model in a new instance.

Hi all I have a collection of new instances of a linq2SQL object. They were created by the default MVC 2.0 model binder. The created instances include a foreign key to an associated model. The created instance does not include an instance of the associated model. I'd like to populate the associated model based on the foreign key. What is...

ASP.NET MVC does not add ModelError when invoking from unit test

I have a model item public class EntryInputModel { ... [Required(ErrorMessage = "Description is required.", AllowEmptyStrings = false)] public virtual string Description { get; set; } } and a controller action public ActionResult Add([Bind(Exclude = "Id")] EntryInputModel newEntry) { if (ModelState.IsValid) { ...

Custom Model binder not firing

This is my custom model binder. I have my breakpoint set at BindModel but does not get fired with this controller action: public ActionResult Create(TabGroup tabGroup) ... public class BaseContentObjectCommonPropertiesBinder : DefaultModelBinder { public new object BindModel(ControllerContext controllerContext, ModelBindingContex...