
April 11, 2011 23:43 by
Brian Keating |
When you crate a new MVC project a view called Error.aspx is created for you in the Views/Shared folder.
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<System.Web.Mvc.HandleErrorInfo>" %>
<asp:Content ID="errorTitle" ContentPlaceHolderID="TitleContent" runat="server">
Error
</asp:Content>
<asp:Content ID="errorContent" ContentPlaceHolderID="MainContent" runat="server">
<h2>
Sorry, an error occurred while processing your request.
</h2>
</asp:Content>
To instruct controller actions to use this Error handler you need to use the HandlErrorAttribute action filter, this is the default exception handler present in MVC.
HandleError is used to specify an exception type to handle and a View (and Master View if necessary) to display if an action method throws an unhandled exception that matches or is derived from the specified exception type.
Some points to note:
- If no exception type is specified, then the filter handles all exception.
- If no view is specified then the default Error view is used.
- As mentioned earlier, exceptions are caught by base types, so it’s important to specify an order catching the most specific exception types first (much like a standard try catch code block.
- The handler won’t get called in debug builds as it checks the HttpContext.IsCustomErrorEnabled (yellow screen of death is preferred)
e.g.
// Dont do this
[HandleError(Order=1, ExceptionType=typeof(Exception)]
[HandleError(Order=2, ExceptionType=typeof(ArgumentNullException, View=ArgNull)]
You’ll need to reverse the order, because if you want the ArgumentNullException to be handled differently, the exception shouldn’t get swallowed by the typeof(Exception) handler.
75fb692c-2262-4d76-be2b-ed4cc3c0f946|0|.0

January 19, 2011 23:26 by
Brian Keating |
In a visual studio 2010 asp page, start typing
<script src=
You’ll get presented with the following screen.
Choose the Pick URL … option and you’ll be presented with the following screen

I think you’ll figure out the rest 
84c6e24a-8ee7-4196-8076-386f28c096a2|0|.0

September 25, 2010 23:35 by
Brian Keating |
A quick sample of how to use linq in your webpages
<% Model.ToList().ForEach(item =>
{ %>
<tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id = item.AlbumId })%> |
<%: Html.ActionLink("Delete", "Delete", new { id = item.AlbumId })%>
</td>
<td><%: Html.Truncate(item.Title, 25)%></td>
<td><%: Html.Truncate(item.Artist.Name, 25)%></td>
<td><%: item.Genre.Name%></td>
</tr>
<% }); %>
I said quick ey! :-)
86ac0ff6-f5f1-44f6-81db-0ab03f8acd49|0|.0

September 8, 2010 20:53 by
Brian Keating |
Hi All,
Been a while since I've writen some posts, been pretty hectic hours at work and weekends building a house so my chances to blog have been limited.
I intend over the coming few days to give a few tips and tricks on MCV2.
Here's on gottya..
Be carefull how you name your formal arguements in your controller functions.
You can see from the screenshot below that I created two args, "Name" and "name"
By default the first matching case insensitive value will be applied to both variables by MVC...
Usually this will be avoided by good naming conventions but be carefull nonetheless :-)

a4c9d13d-181f-45db-8fd1-ea3c5cb80ee6|0|.0

June 29, 2010 23:07 by
Brian Keating |
Pre .NET 4.O
Prior to ASP.NET 4.0 (and especially with MVC) when a user outputted information to a webpage they used <%= Server.HtmlEncode(modelViewStore.Content) %>
The reason for the Encoding is primiarily to prevent XSS (cross site script injection) whereby someone may try to inject some client side script or HTML Markup to vandalize a site or to steal valuable information.
This approach has a few shortcommings; like,
* Users may forget the encoding
* bit verbose
.NET 4.0
A new nugged has arrived:
<%: modelViewStore.Content %>
48453ee0-aa43-4149-a19e-e58610d2c963|0|.0