Posts

Breaking? Change In Asp.Net MVC2

In MVC1, by default an empty textbox was sent as string.Empty to the controller on POST. In MVC2, it now sends the value as NULL. See ModelMetadata.ConvertEmptyStringToNull . I think there are some valid reasons for why they made the change – see Brad Wilson’s comment for more. If your system relies on string.Empty, you’ve got a problem. There are several options for handling this. The first is using the DisplayFormatAttribute on every property that needs it. Painful. Here’s an example: [DisplayFormat(ConvertEmptyStringToNull=false)] public string FirstName { get; set; } You can also write a custom binder that sets this value to false. Like so: public class CustomStringModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (bindingContext.ModelType == typeof(string)) { ...

Navigation Using Areas in Asp.Net MVC

Asp.Net MVC2 introduced Areas as a feature part of the framework. Areas allow you to divide your application into logical units. It also makes your Url’s look more accurate. Thinking of a generic store they might have areas such as Inventory, Payroll, Employees and Sales. Here are example ActionLinks for each area. <%= Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { })%> <%= Html.ActionLink("Payroll", "Index", "Main", new { area = "Payroll" }, new { })%> <%= Html.ActionLink("Inventory", "Index", "Main", new { area = "Inventory" }, new { })%> <%= Html.ActionLink("Employees", "Index", "Main", new { area = "Employees" }, new { })%> <%= Html.ActionLink("Sales", "Index", "Main", new { area = "Sales" }, new { })%> Notice that the area is pass...

Lose your Find / Replace window?

Working in VS2010, I suddenly lost my Find /Replace window. I found this post from Rick Strahl but unfortunately that doesn’t work for me since ALT-M is mapped as a menu shortcut. Solution: Window –> Dock. This will dock the window and then you can move it to your desired location. Cheers!

Visual Studio/SQL Server Management Studio Find and Replace with Regular Expressions

Image
I needed to format a bunch of strings in SQL Management Studio (this works for VS also) and finally took the time to figure out Find/Replace with Regular Expressions. The first thing to note is that VS/SSMS use different regex codes (don’t know why but I’m sure they have their reasons). You can find the list of codes here . I have list of 3 strings containing 10 digits followed by a space and then 3 letters. I wanted to replace the digits with the word Descriptor. Here’s my data: 1234567870 ABC 1234567880 DEF 1234567890 GHI Here’s my find expression: [0-9]^10 {[A-Z]^3} Here’s my replace expression: Descriptor: \1 Here’s my result: Descriptor: ABC Descriptor: DEF Descriptor: GHI The key is the {} brackets and \1. The {} brackets tell the engine I want to keep whatever matches the expression. This is called a Tagged Expression. The \1 says place the first tagged expression here. I can create multiple tagged expressions and place by using \1, \2, etc. I can even chan...

Asp.Net MVC, Forms and Missing Values

Remember, Asp.Net requires that you use the Name and not just ID on your form controls. If you don’t, they don’t come along for the ride to your controller.

RedBox “Verify Your Subscription” Emails

Anytime I get an unsolicited email saying “verify” something, I’m suspicious. I’ve gotten three of these emails lately. Checking the links, they seem to be genuine. I also found this on Facebook, that seems to indicate they are real. Did notice that lady hadn’t been able to use her code. Think I’ll give it a try and see what happens.

Cache and Compress in Asp.Net MVC

Image
Found a good entry on caching at the user browser and compressing the response. Note: It’s from some early beta stuff so be sure to change FilterExecutingConext to ActionExecutingContext. More on that here . Enjoy! Subscribe in a reader