web 2.0

Building Better MVC Code with T4MVC

If you are a ASP.NET web developer than chances are that you have heard of or dealt with problems related to “Magic Strings”. Magic strings are taboo because they introduce a degree of fragility in your code due to the fact that they are not strongly typed. The classic example, is referencing a View Name or Route in your controller action using a string value: public class HomeController : Controller { public ActionResult Index() { return RedirectToAction("Foo"); } public ActionResult Foo() { return View(); } } As you would expect, when the Index action is invoked the user gets redirected to “Foo”. Unfortunately, if I rename the “Foo” method to “Bar” my code will still compile but it will ultimately fail at runtime. This is all due to the fact that are RedirectToAction method is using the magic string “Foo” which is not strongly typed and therefore not caught by the compiler. As a workaround to this ... [More]

Looking for an MVC Grid Control? Try MVC Contrib!

Like most .NET Web Developers I was ecstatic when MVC was released. To put it plainly, I hate WebForms. However I do find myself missing some of the great WebForm controls like the DataGridView. The DataGridView was present in every WebForm application that I wrote. I really appreciated all the subtle bells and whistles that Microsoft added to the grid over the years. I wrote my own grid control for classic ASP and I know firsthand that it is a significant undertaking to make a grid control that if feature rich and flexible enough to handle complex situations. Therefore I was not crazy about taking on the task again… Initially, I adopted jqGrid as my new de facto grid control. From a end user’s perspective, jqGrid provides a top-notch user experience. Unfortunately, the control is heavily dependent on JavaScript so its not always the best solution for Mobile websites. In addition, jqGrid does require a fair amount of plumbing. Although it’s not difficult to implemen... [More]

Tags: ,

ASPNet | dotNet | MVC

Error Handling in MVC with ELMAH

What is ELMAH? In case you have been living under a rock I will start this block post by giving you a basic introduction to ELMAH. If you already are familiar with ELMAH then just skip to the next section. The following description was taken verbatim from the ELMAH website… ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment. Once ELMAH has been dropped into a running web application and configured appropriately, you get the following facilities without changing a single line of your code: Logging of nearly all unhandled exceptions. A web page to remotely view the entire log of recoded exceptions. A web page to remotely view the full details of any one logged exception. In many cases, you can review the original yellow screen of deat... [More]

How to Build a Custom View Engine with Theme Support

All good blogging platforms have theme support. So while working on WeBlog I initially implemented theme support by using a base controller class. The base controller class was responsible for dynamically setting the master page at runtime. I did this by assigning the action’s MasterName property in the OnActionExecuted event. Here is a short snippet of code which outlines the process. public class BaseController { protected override void OnActionExecuted(ActionExecutedContext filterContext) { var action = filterContext.Result as ViewResult; if (action != null) { action.MasterName = MyApp.Properties.Settings.Default.Theme; } base.OnActionExecuted(filterContext); } } Although the BaseController concept worked, I never liked that fact that all my other controllers had to inherit from it. As a matter of fact, when I added the BaseController class to my project I made myself an action item to research Custom View E... [More]

Advice for Aspiring ASP.NET Web Developers

For some reason, I have been asked the same question a lot lately. Which is, "I am new to development. Do you have any tips/tricks/suggestions to get me up to date on ASP.NET?". My knee jerk response to this question is usually to point people to Google for the answers. However, there is so much information floating around on the web these days that it can be overwhelming when you try to comb through it all. So, if you are an aspiring ASP.NET web developer then I hope you will find the following links, tips and tricks useful. The Basics of Web Development No matter what web technology you develop with, there are some basics that you should understand first: HTML – If you have never had exposure to HTML then you are going to want to visit W3 schools tutorial page before going any further. In its most primitive form, HTML is very simple and easy to use. Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation semantics (that is, the look and form... [More]