Clicky

One of the most amazing features of ASP.NET MVC is its powerful routing engine that let you define clear URLs for your web application. Today I want to share a very simple and short tip with you to handle non-English URLs in your ActionLink methods.

Let’s start with an example; in a blog engine we have two routes as follows:

routes.MapRoute(
                "ShowPost",
                "read/{url}",
                new { controller = "Post", action = "Show" }
            );
 
routes.MapRoute(
                "EditPost",
                "edit/{url}",
                new { controller = "Post", action = "Edit" }
            );

and you decide to show a Persian title in a URL as follows: /blog/read/این-یک-عنوان-است

Everything is fine till now but if you want to put an ActionLink in your view to redirect user to edit page in this way:

<%= Html.ActionLink("Edit", "Edit", new { url = Model.Url }) %>

You will be redirected to an ugly encoded URL like this /edit/%D8%AA%D8%B3%D8%AA instead of /blog/edit/این-یک-عنوان-است

Here’s the simple trick to overcome this:

<%= HttpUtility.UrlDecode(Html.ActionLink("Edit", "Edit", new { url = Model.Url })) %>

That’s it!

kick it on DotNetKicks.com Shout it


 
Categories: ASP.NET MVC | i18n | Web Development

April 20, 2009
@ 11:13 AM

It's about one month that ScottGu and his team have released ASP.NET MVC 1.0 but still there aren’t numerous books on this topic available in the market. As I know by far, these titles are available to purchase: ASP.NET MVC Framework Preview and ASP.NET MVC 1.0 Quickly. I know there are many articles and blog posts containing valuable information and tutorials to start learning ASP.NET MVC but many developers prefer to read books because they are better structured to learn something. From the earlier previews, authors that had been starting to write books on this topic offered some sample chapters to introduce them to the community (and they are still doing) so I decided to list all (or at least most) of them here for a quick access. My list contains both PDF sample chapters as well as link to some authors’ blog posts which contain draft unedited versions of their books:

As Wrox has announced, Professional ASP.NET MVC 1.0 is to be published in April and we’re close to see what ASP.NET team have done as a book for ASP.NET MVC developers!

kick it on DotNetKicks.com Shout it


 
Categories: ASP.NET MVC | Book Review | Download | eBooks | Freebies

A few days ago I had a chance to see a tweet from Wrox inviting users to participate in a private review access to ASP.NET MVC 1.0 Website Programming: Problem - Design – Solution and fortunately I was among those 10 lucky guys who  gained access to the first eight chapters of the book (it sounds good that authors are starting to offer sample chapters in private or public preview forms like what ScottGu has done by publishing the first chapter of Professional ASP.NET MVC 1.0). Meanwhile I don’t want to write a classic review post about this book because the book is not yet officially published and also I don’t have access to other chapters. I just want to thank Wrox guys and book authors to do this and I’m sure such movements will increase Wrox books quality.

What I want to talk about in this blog post is a very good ‘How to’ section in chapter 2 of this book: ‘How do I choose between MVC and Web Forms’. It has been a common question among all ASP.NET developers since the first preview releases of ASP.NET MVC and many guys in the community have wrote posts and articles about it. The last discussion I remember on this topic was Rachel Appel’s session at MIX ‘09 titled ‘Choosing between ASP.NET Web Forms and MVC’ (you can also download a high-res video here) that was very useful. After reading the book preview chapters I found a very good and practical way to rank your real need in the book and it was a worksheet to help you make the right decision for a project; as we read in the book:

After publishing this post I found out that author has already posted about this on his own website. So to respect his and Wrox Press rights I removed the mentioned section from chapter 2 of the book and you can read about it at http://www.coderjournal.com/2008/12/introducing-aspnet-mvc-part-2-aspnet-mvc-vs-webforms/ 


P.S.: I want to thank Nick Berardi, Al Katawazi and Marco Bellinaso, that are the book authors, for their cool book :-)

P.S. (2): As I found out (after publishing this post, and I swear I haven’t ever seen that) there is an original post about this by Nick Berardi and so I reference it here and I may remove the whole post content except this link if Nick or Wrox request (I did it) that but it seems that someone likes to argue about this more than what the owners of the book should do. Dear Lee! I don’t need to get impression as you said; I just wanted to spread a good word and thank them but you introduced me as a community killer and I’m so sorry for you!

kick it on DotNetKicks.com


 
Categories: ASP.NET | ASP.NET MVC | Book Review