Monthly Archives: January 2013

T4MVC: String-free ASP.NET MVC

One of the few not-so-beautiful parts of ASP.NET MVC is that you have to use strings to refer to your controllers, actions and views. If you ever created an MVC project you probably write something like this into an action:

  return View( "Index" );

or this into a view:

  @Html.ActionLink( "Click here to sign in", "Login" )

The pain points are the strings, because the smallest mistake results a runtime error.

The T4MVC project can help you to solve this problem with strongly typed helpers. The best way to include it into your project is to add it via the NuGet Package Manager:

t4mvc-nuget

If you already have controllers in your project, don’t be surprised that the installer will slightly modify them:

t4mvc-warnings

And you will get some extra files as well:

t4mvc-files

But thanks to all that, you can use strongly typed values to refer to views:

  return View( Views.Index );

actions:

  @Html.ActionLink( "Bejelentkezés", MVC.Home.Login() )

any many other components – that you can learn more from the documentation.

Because all magic is done via code generation based on T4 templates in the background, you may wonder what happens when you add a new action. You will see that you can immediately use it in your view, it will appear immediately in IntelliSense, but unfortunately it will fail in runtime with the following error (this is the moment when you can think about whether it is not exactly what you wanted to avoid):

T4MVC was called incorrectly. You may need to force it to regenerate by right clicking on T4MVC.tt and choosing Run Custom Tool

Thanks to the perfect error message, if you follow it, your issue will be solved. However, you may find the AutoT4MVC extension more convenient, which monitors your files and folders and automatically regenerates the files when required.

 

Technorati-címkék: ,
Advertisements

Firefox vs UTF-8

I had an unusual issue while I was updating the MSDNAA site of our university: the pages rendered correctly when I opened them from my own computer, but not from the server. Almost all browsers displayed them perfectly, except Firefox that showed ugly characters instead of the special Hungarian accented chars.

I checked the files, all of them were saved correctly in UTF-8 with the byte-order-mark in the beginning – which was not hard to recognize thanks to Firefox that rendered them on the page: 

Because the site now consists of brand new HTML5 pages, all page contains the <meta charset="utf-8" /> line, but I also added the classic Content-Type line for sure – in vain.

After the quick checks, back to Rule #1: When in doubt, start Fiddler! Fiddler showed me the following header in the response:

Content-Type: text/html; charset=iso-8859-1

This was the moment when I understood why the old files were all saved in ISO-8859-1: because this header is forced by the webserver! And the setting in the header overwrites the setting in the page – at least in Firefox now.

Because the site runs on Apache in a shared hosting environment without ASP.NET, PHP or admin access, server side code was not an option to overwrite the header. None the less the final solution became quite simple. I just added this single line to the .htaccess file in the root of the site:

AddDefaultCharset UTF-8

The settings in the root are applied to the subfolders as well.

 

Technorati-címkék: ,,

.NET Interview Cracker blog

In a job interview you can face with several topics. Even if you are applying for a C# developer position, you have a fair good chance that you will get a few general .NET, database- or webservice-related questions. Of course there are several checklists available online that try to cover these topics one by one, but Chandan Kumar Sinha, a software developer from India, thought that a blog could be a better format.

On the .NET Interview Cracker blog he publishes about 2-3 posts every week and touched C#, .NET, SQL and webservices so far. The posts are not in question-answer format, but instead he summarizes the most important aspects of the topics. This format is great also for professional developers, because it helps to refresh and set out long learned concepts.

 

Technorati-címkék: ,,,

jQuery breaks with old IE versions

jquery-logoThe latest, 1.9 version of jQuery was released today, together with the beta of the 2.0 version. Although both versions share the same API (some features were removed from 2.0 as well as from 1.9), there are huge differences between them:

  • The 1.9 version – just like the previous versions – runs on Internet Explorer 6, 7 and 8, or as they say, on “oldIE”.
  • The 2.0 version will not run on oldIE. This decision results a simpler, faster and smaller library.

According to the Release Notes, both versions will be supported in the future, but I’m afraid that support will not last for ever. Sooner or later the 1.9 version will be deprecated, and new features will be implemented only in the 2.0 version.

Who loses more on this, IE or jQuery? Developers will switch to other libraries, or websites will render IE 6-7-8 obsolete?

 

Technorati-címkék: ,,

Phil Haack in IT Business

Having a break during the final exams I got my hands on the July 2012 issue of the Hungarian IT Business journal:

it-business-1

I’ve started reading the articles till on page 15, in an article about how to learn driving online, I’ve seen a familiar face (the article is available online too):

it-business-2

ASP.NET old-timers will probably recognize these guys: he is Phil Haack the creator of ASP.NET MVC and NuGet with his brother. You can find the original image here in a very good blog post: http://haacked.com/archive/2008/11/06/usability-vs-discoverability.aspx

IIRC, Phil had a Twitter post about this picture, copyright and websites about learning to drive.

 

Technorati-címkék:

Telerik Software Craftmanship Calendar

New year, new calendar, and nothing looks better on a software developer’s wall, than Telerik’s Software Craftmanship Calendar:

telerik-calendar

In this calendar you can read a monthly geek wisdom on every page and thanks to the creative images, it will be hopefully stored deep in your lizard brain. Because January is about Keep It Simple, I stop for now, but you can read more about the calendar here: http://nimblepros.com/products/software-craftsmanship-2013-calendar.aspx

Many thanks to Steve Smith for the calendar!

 

Technorati-címkék: