Search Wiki:

ASP.NET MVC 2 Code Examples


This page contains ASP.NET MVC code examples based on the latest release: ASP.NET MVC 2.

You can download the following code examples and use the links to browse to the associated topics in the MSDN documentation. All samples are provided in both .cs and .vb versions.

For more information about ASP.NET MVC, see ASP.NET Model View Controller (MVC) on MSDN.

If you have questions or problems with any of the samples, please post your comments on the MVC Forum

Code Example Download Related MSDN Topic
MVC AJAX Application Download Walkthrough: Adding ASP.NET AJAX Scripting to an MVC Project
MVC Areas Application Download Walkthrough: Organizing an ASP.NET MVC Application using Areas
MVC Asynchronous Controller Download Using an Asynchronous Controller in ASP.NET MVC
MVC Basic Walkthrough Download Walkthrough: Creating a Basic MVC Project with Unit Tests in Visual Studio
MVC Controller Download System.Web.Mvc.Controller class
MVC Data Views Download Walkthrough: Using MVC View Templates with Data Scaffolding
Using the Templated Helpers to Display, Edit and Label Data Download Walkthrough: Using Templated Helpers to Display Data System.Web.Mvc.Html.DisplayExtensions class
Validating Model Data Using DataAnnotations Attributes Download How to: Validate Model Data Using DataAnnotations Attributes
Remote Validation Download How to: Implement Remote Validation from a Client in MVC
Using TDD with MVC Download Walkthrough: Using TDD with MVC
Last edited Sep 8 2010 at 12:59 AM  by ricka0, version 28
Comments
vinayakbaddi wrote  Dec 14 2010 at 10:48 AM  
I'm unable to download any of the link stated above. Please correct this... a mail reply to me on the same would be great.

kingdom_0 wrote  Mar 23 2011 at 2:27 AM  
I'm unable to download any source too,notice me while the problem solved

Levitikon wrote  Jul 19 2011 at 9:48 PM  
The "MVC Areas Application" Download project has errors:

Server Error in '/' Application.
The view at '~/Views/Home/Index.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The view at '~/Views/Home/Index.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The view at '~/Views/Home/Index.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>.]
System.Web.Mvc.WebFormView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +315735
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +303
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260
System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8920029
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

DieselUofA wrote  Jan 20 at 8:12 PM  
Download Links DO NOT work. Please Fix.

bennsolo wrote  Feb 28 at 6:23 AM  
Hi All, you can get some of the samples from
http://archive.msdn.microsoft.com/aspnetmvcsamples/Release/ProjectReleases.aspx?ReleaseId=3038
http://archive.msdn.microsoft.com/aspnetmvcsamples/Release/ProjectReleases.aspx?ReleaseId=3547
http://archive.msdn.microsoft.com/aspnetmvcsamples/Release/ProjectReleases.aspx?ReleaseId=3269
http://archive.msdn.microsoft.com/aspnetmvcsamples/Release/ProjectReleases.aspx?ReleaseId=5114
Hope this is helpful.

Updating...
Page view tracker