Model binding a collection with MVC and .NET 2.0

After about 3 hours of frustrating debugging, I came across a quirk/bug when using: MVC .NET 2.0 / 3.5 Model binding a collection Imagine you have a collection of, say User objects.  And you would like to bind that collection to your view, but you only want to display some of the users.  For example, only admin users.  Your … More Model binding a collection with MVC and .NET 2.0

Unit Testing: Using Extension Methods for better Exception Catching

Improving unit testing, and use some sleek OOP too. Let’s say that we want to test a call to a basic stored procedure, where @ClientID is required. EXEC MYDB.MYSCHEMA.GetClients @ClientID = 10001 Now we want to test the database call in a unit test.  If we don’t pass in @ClientID, we should expect a SqlException, … More Unit Testing: Using Extension Methods for better Exception Catching

DBNull – Using ToString() vs. Casting

You can use ToString on any indexed value in a DataRow, and it will return null if the field is DBNull: string myNullableField = row[“MyField”].ToString(); However, if you try to cast that same field as a string, you’ll get an exception: string myNullableField = (string)row[“MyField”]; //InvalidCastException! But, the good thing about the InvalidCastException being thrown, … More DBNull – Using ToString() vs. Casting

About the Author

I would rather destroy the box than think inside it. Rob Wilson is an OOP software developer and engineer based in the Atlanta, Georgia area.  He specializes in web design and .NET/C# web development with SQL Server.  He works for a medical practice management / business intelligence software company in Atlanta as a software developer. … More About the Author

How to include / import a namespace in an MVC View

Tired of all of those crazy-long namespaces all over your view? Add the using statement to your view if you are using the Razor engine: @using My.Namespace.Path  @{ ViewBag.Title = “My Page”; … } <html goes here> … </html> OR Add the import statement If you are using the ASP.NET (C#) engine: <%@ Import Namespace=”My.Namespace.Path” %>  <html goes here> … More How to include / import a namespace in an MVC View

How to Ignore Whitespace in Visual Studio with Team Foundation Server

Basically, we are going to add a command line argument to the tool that Visual Studio uses to compare files.  The tool is called diffmerge.exe, and we are going to add the /ignorespace argument when this is ran. Open Visual Studio. Navigate to Tools –> Options. Browse to Source Control on the left and click … More How to Ignore Whitespace in Visual Studio with Team Foundation Server

Hello, World!

Now, how did I do that again? CodeRob is my blog to share software development tidbits from my experiences in .NET, SQL Server, ASP.NET/C#, HTML/CSS, jQuery, and whatever shenanigans I get into in my working life. It’s also for those nuggets of information that I need when I say, “Now, how did I do that … More Hello, World!