Tuesday, October 15, 2013

Custom View Engine in ASP.NET MVC 4

Custom ViewEngine? Do we really need this? Generally not. But I needed this in a project. In the project I needed to override the ViewEngine.

The override ViewEnging looks like follows:

public class MyViewEngine : RazorViewEngine
    {
        public MyViewEngine()
        {
            ViewLocationFormats = new string[]{
                "/Views/Themes/{0}.cshtml",
                "/Views/{1}/{0}.cshtml"
            };
        }
    }

And then in the Application_Start of Global.asak, add the following

protected void Application_Start()
        {
            // ... other code

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new MyViewEngine());

            // ... more code
        }

Wednesday, October 09, 2013

Email template background image in Outlook Client

Working with email template is really painful. In the era of HTML5, CSS3 and Javascript, we still need to work in table design because of email clients. Here I am concentrating about the Outlook email client where the background image don't work traditional.

If we want to put a background image in a table row then we need to code as following

<tr class="back" style="height: 38px; background: url(imagepath) no-repeat;">
 
 <td width="70%" style="height: 38px; padding: 0 10px;">
  Cell text
 </td>
 
</tr>