Display Attribute Not Working With ASP.NET MVC 2 RTM
Published on August 25th, 2010.
Recently I was asked about a strange problem concerning the Display attribute in ASP.NET MVC 2. The problem was the Display atribute had no effect in the view. It was really a strange one. I tried it myself and it was true.
Let’s have a look at that situation. Below is the model for a user.
public class User { [ScaffoldColumn(false)] public int Id { get; set; } [Required] [Display(Name = "User name")] public string Name { get; set; } }
Using Html.DisplayForModel() in our view results in the following web page:
As you can see the Display attribute has not been taken into consideration at all. The reason for this is ASP.NET MVC 2 RTN do not know about it. Display attribute is new for .NET 4 and ASP.NET MVC 2 RTM is compiled under .NET 3.5. This attribute is supported in Futures release of ASP.NET MVC and will be supported in any newer releases (like MVC 3).
OK, but I didn’t give you a working solution so far. Well, there is – DisplayName attribute. Note that it resides in System.ComponentModel not in System.ComponentModel.DataAnnotations. Our model now looks like this:
public class User { ... [Required] [DisplayName("User name")] public string Name { get; set; } }
Filled under ASP.NET MVC. No Comments.
protected internal exposed
Published on August 23rd, 2010.
.NET gives developers a lot of freedom. In every version new features are added to ease them in their daily work. One of the simplest things that have existed since the first versions of .NET framework are access modifiers. Using them one sets the access to a specific class/method. Public, private, protected… all are standard modifiers. If you have experience with an object-oriented language you must know them by heart. .NET provides another modifier – internal. It allows access to a method only in the parent assembly (the one the corresponding class resides in). (more…)
Filled under .NET, C#. No Comments.
ASP.NET MVC DI with Common Service Locator and NInject
Published on August 5th, 2010.
I think everyone knows about Dependency Injection (DI) and how important it is when it comes to building low-coupled components. There are many IoC (Inversion of Control) containers. The most popular are
Each of them has its own pros and cons. I have been using NInject for years and I am really happy with it. Autofac is quite a new DI framework which shows really good results on benchmarks. You can find information for all DI frameworks on their websites or just google them for comparison. (more…)
Filled under ASP.NET, Design Patterns, Development Techniques. 1 Comment.
Test-Driven Development with ASP.NET MVC
Published on August 3rd, 2010.
ASP.NET MVC has become more and more popular. In my previous post I gave you my vision about it and what it introduced to ASP.NET developers. One of the advantages of the MVC pattern is the better testability. You can easily test every controller without dealing with the View itself.
Test-Driven Development (TDD)
Principles of TDD are really simple. The entire TDD process is described on the following scheme:
Filled under ASP.NET, Design Patterns, Development Techniques, Testing. No Comments.
Why is ASP.NET MVC so Popular?
Published on August 2nd, 2010.
Classic ASP.NET
ASP.NET MVC has become more and more popular. Why? The ordinary ASP.NET allows developers to abstract from many details like request/response headers (by wrapping everything in nice API), manual HTML coding (by using server-side controls), etc. Everything is really cool – we develop a Web site for seconds. But what about the maintainability of this site later? Customers always want more and more. Even after years they may ask you to implement a new feature for them. And then developers start to sink into the depth of their own code ocean. If we add the lack of good documentation, the entire situation becomes really bad. (more…)
Filled under ASP.NET, Design Patterns. 1 Comment.

