Archive for 'ASP.NET'

ASP.NET localization with Umbraco

Umbraco is very neat and easy to integrate with ASP.NET, probably because it was built on it. One typical scenario is to create a multi-lingual web site with Umbraco, which automatically requires the use of localization. Umbraco supports localization very well and there are two main techniques, I can think of – using a dictionary or using a special page with custom fields. I personally prefer the latter, because one can use nicer names and descriptions for the custom fields, so it is easier and more intuitive to edit the texts.

Umbraco Localization Structure It is a good idea to create a separate branch in Umbraco for each language in your website. You should keep the language-independent settings in the root node and all language-dependent ones in the branches.

The next step is to use this localization in your custom controls in ASP.NET. Umbraco has a nice control, called item, which can display the contents of a property. By default, this control tried to look up the property in the current node, however you can also specify a node by its id. So, one solution is to use this control and specify the node ID of your Texts node every time (or create some wrapper over this control). However, I find this way very clumsy in spite of the nice properties the item control provides. (more…)

Filled under ASP.NET, CMS, Umbraco. No Comments.

Display Attribute Not Working With ASP.NET MVC 2 RTM

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. 2 Comments.

ASP.NET MVC DI with Common Service Locator and NInject

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. 3 Comments.

Test-Driven Development with ASP.NET MVC

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:

(more…)

Filled under ASP.NET, Design Patterns, Development Techniques, Testing. No Comments.

Why is ASP.NET MVC so Popular?

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.