model-binding

Html.ActionLink (): new { route value} is acting strangely. I don't know where length = 17 parameter is coming from

Hello, I've this link on a page <% = Html.ActionLink(item.Title, "Edit", "ArticleManagement", new { id = item.ArticleDataID })%> and a simple method to receive the article Id public ActionResult Edit(int id) { //Do something } Unfortunately, I'm getting an error" parameter dictionary contains a null value ...

How to customize the "The value 'foo' is not valid for Number." error message?

[MetadataType(typeof(PersonMetaData))] public partial class Person { public class PersonMetaData { [Required(ErrorMessage="The number is required")] public object Number {get;set;} } } This error message is shown when the number field is empty and when there's an invalid input it gives "The value 'foo' is not va...

How can I allow period and comma as valid decimal point separators for floats?

I would like to allow both "123.45" and "123,45" as valid decimal inputs but currently "123.45" results in "The value '123.45' is not valid for Foo". ...

Modelbinder creates a foreign relationship unnecessary.. how to solve?

I have a Product entity that has a foreign key relationship to Manufacturer. I want to make it optional whether user adding a new product wants to set a manufacturer. In my create view I have, <%= Html.LabelFor(p => p.Manufacturer.Name) %> <%= Html.EditorFor(p => p.Manufacturer.Name) %> In create action, public ActionResult Create(P...

How to support multiple forms that target the same Create action on the same page?

I want to have two separate forms on a single create page and one action in the controller for each form. In the view: <% using (Html.BeginForm()) { %> // Contents of the first (EditorFor(Model.Product) form. <input type="submit" /> <% } %> <% using (Html.BeginForm()) { %> // Contents of the second (generic input) form. ...

Model binding issue in LINQ to SQL

I am just now starting to work with LINQ, and am pretty familiar with MVC. I have a strongly typed view that is updating a record. I have successfully done a creation: This works fine, and creates a record in the database: public ActionResult Create(TABLEMODEL tableModel) { DBDataContext db = new DBDataContext(); if (ModelState...

ASP.NET MVC Partial Model Binding from Stored Procedures

Currently, I have a set of stored procedures which are called to populate different fields on a page. I am calling the stored procedures from the LINQ to SQL class that I dropped them on, which works fine. However, it automatically generates (StoredProcedureName)Result class names which I have to work with. Is there anyway to take a s...

How to send jQuery $.get so the Model Binder can bind a string to a parameter?

I'm having difficulty getting the Model Binder to work. I thought it was the jQuery, so I asked this question, but after further investigation, I can see that the jQuery is indeed sending the parameter to the server. That's the reason I'm asking a new question - this is no longer a jQuery issue, as I originally thought. Background: Wha...

ASP.NET-MVC2: Why does TryUpdateModel ignore properties after the second level of the object model tree?

Perhaps I'm missing something here, but it seems that anything in the object model tree 3 or more levels down, is ignored when using TryUpdateModel. For example (simplified): public virtual ActionResult SomeAction(int id, FormCollection form) { IValueProvider vpFrom = form.ToValueProvider(); /* At this stag...

Can I pass an enum into a controller so the Model Binder binds it?

if so, how should i pass the parameter? would a string matching the enum name be ok? This would be handy if I was passing a dropdown box that matched enumerated items. It would be useful to use a solution presented in this answer if I could just as easily bind to the enum when I submit the data back. ...

MVC 2 asp.net VC2010: Where happens the "databinding"?

Understanding question: 1.) "X_IndexViewModel" class public class X_IndexViewModel { public List<SelectListItem> CheckBox_1 { get; set; } ... } 2.) XController.cs public ActionResult Index() { X_IndexViewModel viewModel = new X_IndexViewModel { CheckBox_1 = new List<SelectListItem>() { ne...

ASP.Net MVC Model Binding

I have a Model that I can bind correctly for display purposes but I can't post an updated version. I can display a page and its list of contents in a form for updating in a strongly typed view. But when I post an updated model i.e. if I changed a pagecontents content then the posted model contains the Pages details but loses the relati...

MVC custom model binder issue

Hi, I have a textbox in my view that i want to receive the value as a List of strings. As example, if anybody enters: tag1,tag2,tag3... receive a List with 3 elements. I did a custom model binder, but im still receiving from the post the string instead the List. This is the stuff that i did: This is my Model: public class BaseItem...

Strongly typed user control model binding not working in Asp.Net MVC 2.0

I am using a strongly typed user control in one of the view. The coding is as follows: This is the call in my View: <table> <% for (int i = 0; i < ((List<string>)ViewData["MyProjects"]).Count; i++) { string viewIndex = "MyTasks" + i.ToString();%> <tr> <td> <%Html.RenderPartial("ProjectTas...

Passing an interface to an ASP.NET MVC Controller Action method

In my ASP.NET MVC app, I have an interface which acts as the template for several different view models: public interface IMyViewModel { Client Client1 { get; set; } Client Client2 { get; set; } Validator Validate(); } So, my view models are defined like this: public interface MyViewModel1 : IMyViewModel { Client Cli...

ASP.NET MVC2 UpdateModel not updating a public property included in whitelist

I have a class Foo with a field UpdateMe of type Confirmation as described below.. public class Foo { public Confirmation UpdateMe{get;set;} public int BarInt{get;set} } public enum Confirmation { N = 0, Y = 1 } I have a whitelist that has UpdateMe, and runs the following way... [AcceptVerbs(HttpVerbs.Post), ValidateAntiForg...

Preventing a model binder from returning a list of null objects in ASP.NET MVC

I have a pretty complex object with numerous datatypes. A few datatypes are Lists (LazyLists to be exact). In my form, I let the user enter up to, say 3 items for this list and my form input names correspond appropriately: myObj[0].Name myObj[0].Email ...consectuviely... myObj[2].Name myObj[2].Email If the user decides to only enter...

MVC2 RTM - model binding complex objects using Entity Framework

I am new to MVC, and am really struggling with what I seems like it should be a very common scenario. I'm using MVC2 RTM, and the Entity Framework for my model objects. What I have working: An edit view for a parent object that contains a collection of child objects. The form displays all the editable fields for the parent, and iterat...

MVC2 Action to handle multiple models.

I've been looking around for an answer to this, which I can't believe hasn't been asked before, but with no luck I'm attempting here. I have a signup form which differs slightly based upon what type of participant the requester is. While writing tests for the solution, I realized that all actions did the same things, so I'm attempting ...

MVC Simple model binding not working

Okay, this has got to be something stupid-as-a-box-of-rocks that I'm doing wrong, but I can't find it. MVC Action: [AcceptVerbs(HttpVerbs.Post)] public virtual ActionResult Create(BatchCreateViewModel createModel) { return RedirectToRoute(MVC.Home.Display()); } BatchCreateViewModel: public class BatchCreateViewModel { bool ...