.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Problem binding a collection to a view model on POST when manipulating the DOM with javascript.

Posted By:      Posted Date: October 08, 2010    Points: 0   Category :ASP.Net

Hi, i'm currently working on a strongly typed view and i'm binding a collection to a table like this:


for (int i = 0; i < Model.Cars.Count; i++)





<%= Html.Hidden(String.Format("Cars[{0}].Id", i),




<%= HtmlTextBox(String.Format("Cars[{0}].CarModel", i),



View Complete Post

More Related Resource Links

How to update a collection of objects in a view model?

I have been trying to design a form, which uses a view model that contains an object array. I want to set up this form so that when the submit button is clicked, all the members of the array are updated. Here is my code:The class definition of the array element:public partial class luSubject    {        public string Name { get; set; }        public bool FilledName { get; set; }public in MasterSubjectId{get;set;}        public luSubject()        {            FilledName = true;        }    }This is the view model I used for the form:public class TestModel    {        public luSubjects[] Subjects;        public int[] MS { get; set; }        public SelectList sl { get; set; }        public TestModel()        {            Subjects = new luSubjects[3];            for (int i = 0; i < Subjects.Length; i++)     &n

MVC Model to View autogeneration problem


Hi all,

Here is the thing. I have the Model "Assignment" created through LINQtoSQL. The Model has an boolean attribute and I would like to associate an Image to each option (true: imgA.png;false: imgB.png) and make it a radio button set.

To do this, I came up with this AssignmentViewModel:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ePortafolioMVC.Models;
using System.Web.Mvc;
using ePortafolioMVC.ViewModels.Classes;

namespace ePortafolioMVC.ViewModels
    public class AssignmentViewModel
        public Assignment Assignment {get;set;}
        public SelectList IsGrupal { get; set; }

        public AssignmentViewModel(Assignment assignment)
            Assignment = assignment;
            var AssignmentValues = new List<AssignmentValue>();
            AssignmentValues.Add(new AssignmentValue(true,"<img src=\"../../Content/images/imgGrupal.png\" />"));
            AssignmentValues.Add(new AssignmentValue(false,"<img src=\"../../Content/images/imgIndividual.png\" />"));

            IsGrupal = new SelectList(AssignmentValues, "ID", "Description", Assignment.IsGrupal);


using System;
using Sys

Problem in passing Json collection object from View to Action



I am trying to send json data from view to controller action.  But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
   public int QuestionId { get; set; }
   public int PrevAnswerId { get; set; }
   public int CurrAnswerId { get; set; }
   public string CurrAnswerName { get; set; }

Json Data look like:
{QuestionId:1, PrevAnswerId:3,  CurrAnswerId:3,  CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7,  CurrAnswerId:7,  CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}

On window load,  I will construct the Json object using "eval()" function and do some operation in the data before its save.

On Save Click, I will call the action through the ajax call.
        url: url,
        type: "GET",
        dataType: 'json',
        data: {score: ScoreJson},

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Model View Controller (MVC) for ASP.NET

Model View Controller (MVC) architectures, immediately wonder how the MVC pattern can be applied in an ASP.NET world. This article will demonstrate how the MVC pattern can be applied to an ASP.NET web application and still maintain the basic Microsoft supplied architecture.

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

WebDev.WebServer.exe has encounted a problem and needs to close when trying to view page in browser


Hi, whenever I load an aspx page in vwde2008, I get the message in the subject of this post.  After I click Ok on that, I get a dialog box, Unable to Connect to the ASP.Net development center.  What can I do to troubleshoot?

I am using Windows XP SP3, vwde2008 with SP1, on a HP desktop.  Also using Office 2003 if that is relevant at all.

Thanks, Justin

Design Patterns: Problems and Solutions with Model-View-ViewModel


The Model-View-ViewModel (MVVM) design pattern describes a popular approach for building Windows Presentation Foundation or Microsoft Silverlight applications. Robert McCarter shows you how the ViewModel works, and discuss some benefits and issues involved in implementing a ViewModel in your code.

Robert McCarter

MSDN Magazine July 2010

Silverlight Patterns: Model-View-ViewModel In Silverlight 2 Apps


In this article, you'll learn how to avoid problematic tight coupling by applying the Model-View-ViewModel pattern in Silverlight 2.

Shawn Wildermuth

MSDN Magazine March 2009

Patterns: WPF Apps With The Model-View-ViewModel Design Pattern


In this article we explain just how simple it can be to build a WPF application the right way using the MVVM Pattern.

Josh Smith

MSDN Magazine February 2009

Design Patterns: Model View Presenter


The MVP pattern helps you separate your logic and keep your UI layer free of clutter. This month learn how.

Jean-Paul Boodhoo

MSDN Magazine August 2006

ASP.NET Grid View Paging and GridDataRowBound Problem -



I have a problem displaying data in a Grid View control when I set a row to visible = false when a certain condition is true.

For example, if a DataRowData value has a condition set to true (custom in table) I set the visible property to false, so the data row will not be visible at run time.

The problem is that I'm using paging (10 rows per page) and if 8 of those rows fall into the true condition that won't show the row, that grid view page will only show two rows of data in page 1. The worst scenario is that if I go to page 2 of the grid view and all the rows (10) fall into the true condition, that grid view page will not show any data at all.

How can I show 10 rows of data at all times in a gridview? In other words, I would like to just show the visible rows at all times.

Any help will be greatly appreciated.


Razor View Engine and Add Namespace in Web.Config Problem



I am working on a MVC project with Razor view engine and I have the following:


This only works if I have on the same view the following:

  @using SquishIt.Framework;

However, on my Web.Config I have the following:


      <!-- Namespaces -->
        <add namespace="System"/>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Ajax"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.Routing"/>
        <add namespace="Microsoft.Web.Mvc"/>
        <add namespace="SquishIt.Framework"/>


So if "SquishIt.Framework" namespace is added on Web.Config why do I need to have the @using on the view?

What's the problem in my javascript's code to get ClientID Property?



 Hi all.

I wirte a simple java script code to get ClientID of controls on the webform. The code is like:

<script type="text/javascript" language="javascript">

var butt = $find("<%= Button1.ClientID %>");



But when i run it , i have a problem. The probmel is:


Server Error in '/' Application.

The Controls collection cannot be modified because t

Entity Data Model and database view returning the same columns as there are in a table


When adding a stored procedure into the Entity Data Model I can select whether the procedure returns a scalar, a (new) complex type or one of the entity types I already defined. 

How do I do something similar for a view?

I mean assuming I have a view like this

CREATE VIEW FilteredFoos as SELECT Foo.* FROM Foo join ... WHERE ...

(that is a view that implements some involved filtering, but returns all columns from one table) how do I add it to the project so that I can use the entity set, but get the Foo objects, not some new FilteredFoo objects.

var foos = myDB.FilteredFoos.Include("Bar").ToList();

foreach (Foo foo in foos) { ...

Thanks, Jenda

Sharepoint 2007 View Problem

I have a document library in Sharepoint 2007 in which I have seet up a number of different views so that the users who work with the information in that library can filter down to the specific area that they work with.  The view itself works great, and they are able to see their data quite easily.  The problem comes when they actually go in and edit any of the items.  Unlike most software in the civilized world for the past 30 years, the user is not returned to the view that they were working with, but to the defult view.  This means that any task where they are required to do many edits at a time becomes a frustrating nightmare and waste of time.  Is there any setting I can change, or anything else at all that I can do to give my users a little relief by making the site navigation such that they are returned after an edit to the same view that they were in before the edit?  Ideally, it would be nice if the same scroll position within the view were returned as well, but I suspect that I may be asking for too much by pushing that issue.  HELP! HELP!  Any and all constructive assistance is appreciated.

Model Binding the values in an HTML Table back to Controller / Model


Currently, I am working with ASP.NET MVC1 and am still learning about Model Binding and how values from a View are passed back to the Controller / Model. Specifically, I want take an existing Model, create a Table and populate the Rows of the Table, allow the user to edit some fields and pass it back.

In my example, I have a Class called "Ingredient" which has 4 public accessors:  Name, Barcode, Amount, and Unit

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcACE.DomainModel.Entities.Ingredient>>" %>

<% using (Html.BeginForm("SubmitOrder","MyController"))
{ %>

<% if (Model != null)
foreach (var item in Model)
{ %>
<td><%= Html.Encode(item.Name)%></td>
<td><%= Html.Encode(item.Barcode)%></
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend