Showing posts with label ASP.NET MVC. Show all posts
Showing posts with label ASP.NET MVC. Show all posts

Thursday, December 16, 2010

Using RouteValueDictionary to test anonymous objects in C#

For example, you have the following anonymous type declaration & instantiation:
var someObject = new {someProperty"someValue"};
How to inspect value of the id property? You need a wrapper, that is able to index anonymous objects. For example, RouteValueDictionary.

Here is code:
var wrapper = new RouteValueDictionary(someObject);
Assert.AreEqual("someValue", wrapper["someProperty"]);

If your ASP.NET MVC controller returns JsonResult, you can use this approcah to test contents of the Data property, which usually references to some anonymous object.

Friday, August 20, 2010

Great ASP.NET MVC 2 (+ EF 4.0) sample

Recently I``ve found a great sample project on the codeplex that shows how to build web applications with ASP.NET MVC 2. I speak about MVC Music Store.



First of all, this project was interesting for me because it demonstrates how to organize data access via Entity Framework 4. There are also a lot of nice stuff in this project, including:

  • Templating, Data Annotations, Validation;
  • View models;
  • Client-side validation, jQuery and AJAX helper methods;

Project includes 80-page PDF walktrough tutorial that describes in details how to create sample application starting from clicking File -> New Project.

You need Visual Studio 2010 and ASP.NET 4.0 to run samples.

ASP.NET MVC 2 is the latest official release at the current moment (ASP.NET MVC 3 is still under development). So, this tutorial is very actual now. I recommend it to everyone who are not familiar with ASP.NET MVC technology. Moreover, this tutorial might be useful if you would like to understand how to use Entity Framework 4 within your ASP.NET MVC website.

Sunday, May 9, 2010

Specifying the default browser for running ASP.NET MVC projects in VS2008

By the default Visual Studio 2008 runs web sites/applications in the Internet Explorer. When you are opening ASP.NET MVC project there is no way in the IDE to change this behaviour. So, if you want to make your ASP.NET MVC project to run in the Chrome, for example, you need to do the following:
  1. Open/create a simple (non-MVC) web site in the Visual Studio.
  2. Select any .aspx file, or the site root in the Solution Explorer window.
  3. Go to File -> Browse with...

Then you need to specify your default browser. If you don`t find the browser what you want in the available browsers list, you can add a new browser by specifying path of it`s executable:


Changes you made are global and affect every web project in the Visual Studio. Now you can switch to your ASP.NET MVC project and enjoy it`s running in your favorite browser.