Mail Templates for ASP.NET MVC

I was working on an MVC project recently, and wanted to use templates for formatting emails.  Scott Hanselmann recommends MvcMailer in this post.  I gave it try, but it has a couple dependencies on other projects, and I wanted to keep it simple and pragmatic for this small project.  

I ended up using ActionMailer.Net which uses two of its own dlls and no external dependencies.  ActionMailer worked for my needs and uses standard views, either .aspx or Razor view files.

Prior to MVC, in web forms, I built an Email Templater, which allowed me to create a new model for each email view, but I had to point the templater to the correct template file location.  ActionMailer is essentially an extension of the MVC ControllerBase class, so all you need to do is place your view files in the View folder of your site.

For my needs it worked, but it is a very basic email requirement I have, so it is possible I may run into obstacles.  But, so far so good.

Tags:

 

ASP.NET MVC Membership

Great starter for getting Membership running quickly in ASP.NET MVC...

http://mvcmembership.codeplex.com/

Tags:

 

Tip: Error Handling in .NET

In .NET development the common approach to exception handling is to make use of Try...Catch...Finally.

try {
  // some code
}
catch (NullReferenceException ex)
{
   // handle the exception
}

Sometimes you don't need to handle the exception and you just want to throw it to the calling application

try {
  // some code
}
catch (NullReferenceException ex)
{  
   throw ex;
}

But, if you do that you will get useless messages while debugging your application.

The better approach is to just call throw without "ex"...

try {
  // some code
}
catch (NullReferenceException)
{  
   throw;
}

This now provides the following error message which is much more useful.

Tags:

 

ASP.NET MVC Setup

First things fist... make sure you have the pre-requisites.  Start by removing any previous or beta versions of ASP.NET MVC.  I start with the ASP.NET MVC Downloads page.

Intall the ASP.NET MVC Framework 1.0 - the one you really need is AspNetMVC1.msi

A couple times an issue has come up where the MVC Project Template is not available when you go to New Project.

Double check that you have the project templates at this location...

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033

The MVC Project template is called MvcWebApplicationProjectTemplate.zip

If it is there and you are not getting it as an option try opening the Visual Studio Command Prompt and running the following commands to install the templates:

devenv.exe /installvstemplates
devenv.exe /setup

If you just want the starter project, you can download the following.

MvcStarter.zip (273.24 kb)

Tags: