background preloader

MVC2

Facebook Twitter

Editing a variable length list, ASP.NET MVC 2-style « Steve Sanderson’s blog. Download the demo project or read on for details.

Editing a variable length list, ASP.NET MVC 2-style « Steve Sanderson’s blog

Update (Feb 11, 2010):Thanks to Ryan Rivest for pointing out a bug in the original code and providing a neat fix. Code updated. Getting Started For this example I’m going to go with the same theme as last time and build a gift list editor. Our model object can simply be the following: public class Gift { public string Name { get; set; } public double Price { get; set; }} Displaying the Initial UI To display the initial data entry screen, add an action method that renders a view and passes some initial collection of Gift instances. public ActionResult Index(){ var initialData = new[] { new Gift { Name = "Tall Hat", Price = 39.95 }, new Gift { Name = "Long Cloak", Price = 120.00 }, }; return View(initialData);} Next, add a view for this action, and make it strongly-typed with a model class of **IEnumerable <h2>Gift List</h2> What do you want for your birthday?

You might also be wondering what Html.BeginCollectionItem() is. Sergio Tapia Gutierrez - Lost in the GC.Sergio Tapia Gutierrez - Lost in the GC. ASP.NET Routing. The topic you requested is included in another documentation set.

ASP.NET Routing

For convenience, it's displayed below. Choose Switch to see the topic in its original location. ASP.NET routing enables you to use URLs that do not have to map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs that are descriptive of the user's action and therefore are more easily understood by users. In an ASP.NET application that does not use routing, an incoming request for a URL typically maps to a physical file that handles the request, such as an .aspx file.

In ASP.NET routing, you can define URL patterns that map to request-handler files, but that do not necessarily include the names of those files in the URL. For example, in the request for the routing parser can pass the values Products, show, and beverages to the page handler. This topic contains the following sections: You typically do not have to write code to add routes in an MVC application. Editable Grid / List Binding in MVC2 « this.Reflect() Steve Sanderson has a great post on how to perform list binding with MVC2 and custom HTML Prefix Scoping.

Editable Grid / List Binding in MVC2 « this.Reflect()

However, it did not demo the out of box functionality that MVC2 provides, so I’m going to do that here. Please note, I’m using MVC2 RC2 in this example. At the end if this post you will be able to download the solution and run/debut it on your machine. The App I’m going to be using Steves sample app. After clicking on that link you will be presented with a grid / list that is editable. This is a order list that is set up in the controller manually. Customer.