ASP.NET MVC

ASP.NET MVC Update Preview 5 to Beta - Part 2

Part one was an in-depth look at upgrading ASP.NET MVC Preview 5 to the new Beta which you can view here. In the above post I talked about the Microsoft Futures assembly and the fact that there was not one yet released for the Beta... Well, in true "Gu" style, Scott Guthrie has written an (another) awesome post on all the new changes and fixes to the ASP.NET MVC Beta, which includes a link to the new Microsoft Futures assembly on CodePlex. Thanks Scott....it was the last thing I was needing in my MVC Preview 5 to Beta update. By...

ASP.NET MVC Update Preview 5 to Beta

Well, I'm biting the bullet and I'm going to update my ASP.NET MVC Preview 5 project to the beta! This Beta is an official release; as the previous "official" release was Preview 3. Lets see how it goes: Step 1 - Install the Beta This kind of goes without saying, but I this is a step by step guide. Make sure all Instances of Visual Studio has been closed, Uninstall ASP.NET MVC Preview 5, then run the Beta Installer: Start up Visual Studio and open your MVC project. Step 2 - Update your assembly references Update the...

ASP.NET MVC Beta - Released!

Has anyone else noticed that Microsoft have released the beta version of ASP.NET MVC? You can get it from here. Happy MVC-ing.... Technorati Tags: ASP.NET MVC,Beta

ASP.NET MVC Action Filter to Detect Mobile Devices Update

Steve asked me in a previous post for a sample application for detecting a mobile device and rendering a mobile view in ASP.NET MVC. You can download a sample MVC app here. The app is the same as the ASP.NET MVC template that the "GU" put together, with the added mobile action filter and views. I've also updated my mobile browser detection. Turns out not to be so straight forward as new phones are coming out all the time with different User Agents etc. This is the best "generic" way I could find: if (filterContext.HttpContext.Request.Browser.IsMobileDevice || filterContext.HttpContext.Request.ServerVariables["HTTP_ACCEPT"].Contains("text/vnd.wap.wml")...

ASP.NET MVC Action Filter to Detect Mobile Devices

One of the great things about MVC is the ability to direct any Controller Action to any named View that you want. This means that I'm able to detect wether the browser is a mobile device and direct them to the Mobile View: public ActionResult Index() { if (Convert.ToBoolean(filterContext.HttpContext.Request.Browser["IsMobileDevice"])) { return View("Index_mobile") } return View(); } This works great. My Index_mobile.aspx view has a Master Page (just like any other view) that sets up the doc type and styles, and I can render the view as normal. The doc type I used is: <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> Another way is to use...

ASP.NET MVC Image Handler

In the "olden days" of Web Forms, to render an image from the database you would have to create a HttpHandler. <httpHandlers> <add verb="GET" path="image.ashx" type="MyApp.Web.ImageHandler, MyApp.Web" validate="false"/> </httpHandlers> In ASP.NET MVC you can now use a Controller Action and View to handle an image. One of the benefits is that it can harness the power of System.Web.Routing and there are no web.config sections to maintain. Step 1 - add a route routes.MapRoute( "MyImageHandler", "image/{id}/{type}.png", new {controller = "ImageHandler", action = "Image"} ); Step 2 - create image handling controller public class FeaturedBusinessesController : Controller { public ActionResult Image(string type, Guid id) ...

Moving from Windows Server 2003 to Vista

My current development machine is Windows Server 2003. Because I'm doing a lot of ASP.NET MVC work, I want to be able to test my applications on IIS7. I've been testing on Virtual Machines and production servers that are running Windows Server 2008, however this is just a bit of a pain while in development. The only way is to upgrade my OS. The easiest way to upgrade would be to Server 2008, however there is licensing issues with using Server 2008 as a development machine. So my only option is Windows Vista. One slight problem is that there is...

ASP.NET MVC Update Preview 4 to Preview 5

As I'm sure you are all aware that the guys have released Preview 5 of ASP.NET MVC Framework. This preview has had a lot of changes since preview 4 and this means a lot of changes to get a preview 4 application building (and running correctly) against preview 5. I have managed to get my application running (eventually!). Here are the main areas that I had to change to get it working: New dlls Almost goes with out saying but you need to reference the new set of dlls System.Web.Mvc System.Web.Abstractions System.Web.Routing ...

ASP.NET MVC Passing querystring to named route

Passing a querystring to a named route in ASP.NET MVC is not well documented. I stumbled across this by mistake! Using  either the Html.RouteLink extention or the RedirectToRoute method it is possible to pass any number of querystring parameters to the route. All you have to do is pass the parameter in the RouteValueDictionary. For it to appear on the querystring the parameter name must not appear on the named route in the RouteCollection. This is easier to explain in code! Route (in Global.ascx.cs):  routes.MapRoute(                 "Default",                 "{controller}/{action}/{id}"             ); using Html.RouteLink: <%= Html.RouteLink("Click Me!", "Default", new { controller = "Home",...

ActiveRecord & the ASP.NET MVC Framework

I have a simple ActiveRecord class: [ActiveRecord] public class Employee {     [PrimaryKey(PrimaryKeyType.GuidComb)]     public Guid? Id { get; set; }       [Property]     public string FirstName { get; set; }         [Property]     public string LastName { get; set; } } I then create a create/edit form on my UI. To update the database is easy with the ASP.NET MVC Framework and ActiveRecord: In my controller: public void Update(Guid? Id) {     var emp = DomainFactory.Get<Employee>(Id);     BindingHelperExtensions.UpdateFrom(emp, Request.Form);     emp.Save();       //Render View } Ok now I want to add a Department Object to the Employee: [BelongsTo(Cascade = CascadeEnum.SaveUpdate)] public Department Department { get; set; } On my form page I create a select dropdown with a list of Departments. The...

ASP.NET MVC Framework Html.Select Gotcha

I have been creating a project that uses the ASP.NET MVC Framework. I am using a select dropdown for the user to be able to select a "Faculty" which is a child object of a "Course". I'm going to use the Html.Select() extension method to do this. So my code goes like this: <%= Html.Select("Faculty", FacultyData, "Title", "Id") %> No problem here, I get my list of Faculties, nice and easy. Right, because I'm know creating the edit page I want this dropdown to have the correct Facility selected when the page loads i.e have a selected value set. The Html.Select takes a fifth property...

WP Theme &Icons by N.Design Studio adapted by timheuer and ruined by rodj!