- How-To: Build Language dropdown with ASP.NET MVC and LINQ
-
Posted by oVan on Wednesday, May 28, 2008 | PermaLink | 0 comments
Here's a quick way to build a language dropdown box with ASP.NET MVC Preview 3, without using a database table. In total we need only 3 lines of code.
1. Controller:
In our controller, we add the following code to the controller action:
List<System.Globalization.CultureInfo> Locales =
System.Globalization.CultureInfo.GetCultures(
System.Globalization.CultureTypes.NeutralCultures).ToList();ViewData["Locales"] = new SelectList(
Locales
.OrderBy(lc => lc.Name.Length)
.ThenBy(lc => lc.DisplayName),
"Name",
"DisplayName");First we create a list of CultureInfo and store it in a variable Locales. For this example I've used NeutralCultures to limit the entries to the most used languages, otherwise you'll get a very long list.
Next we create a ViewData object and fill it using SelectList, passing along our Locales variable.
Note: I've sorted Locales twice, first with OrderBy and then with ThenBy. As parameter we throw in a Lambda expression to transform our Locales and get the member we want. The reason I sort on Name.Length first is that the Invariant CultureInfo has an empty Name and thus it will be sorted to the top of the list.
After that we simply render our View (in this case passing along a Contact record from the database.
2. View:
The code in our view is even simpler. With the help of Extensions and MVC HtmlHelper objects we have our dropdown box in no time:
The only line of code to render the fully functional html select dropdown box is this:
<%=Html.DropDownList("Locales") %>
Here is the final result:
A quick look at the produced code shows us the clean XHTML underneath:
<select name="Locales" id="Locales">
<option value="">Invariant Language (Invariant Country)</option>
<option value="af">Afrikaans</option>
<option value="sq">Albanian</option>
<option value="ar">Arabic</option>
<option value="hy">Armenian</option>
<option value="az">Azeri</option>
<option value="eu">Basque</option>
<option value="be">Belarusian</option>
<option value="bg">Bulgarian</option>
...Ps: in the screenshots above I've used a test version of TheSansMono OpenType by Luc(as) de Groot. This font will be published soon on the LucasFonts website, together with TheSansCondensed OpenType. Typographer Luc(as) de Groot is also known for the Calibri and Consolas fonts in Windows Vista and Microsoft Office 2007.
- FIX: GoogleBot produces "Cannot use a leading .. to exit above the top directory" in ASP.NET
-
Posted by oVan on Sunday, April 06, 2008 | PermaLink | 0 comments
I found numerous "Cannot use a leading .. to exit above the top directory" errors in my Elmah-logs lately, all of them generated by the ASP.NET engine after a visit from GoogleBot. It is caused by using URL rewriting in your aspx-pages in order to have more readable URL's and better search engine rankings.
Funnily, this only started after I submitted dynamically generated sitemaps to the Google Webmaster Tools for my clients websites. Instead of improved ranking and indexing, however it resulted in exclusion of all failing URL's.
For more background information about this error, which is generated only for certain user agents including GoogleBot and Yahoo! Slurp, you can do a simple Google search. There are a few solutions to fix this, but most involve using a custom base page class or creating different .browser files for each problematic user-agent in the App_Browser directory. Having done custom browser.ini solutions with Browserhawk years ago, I did not feel like starting all over again with googlebot.browser, yahooslurp.browser etc.
By far the easiest solution is a simple change in your web.config:
Find the <authentication> section, then change the <forms> line by adding:cookieless="UseCookies"
Voila, the problem is fixed. Note that this disables cookieless functionality for forms, so if you really need that you should use a different solution.
Labels: .NET, asp.net, browser, bug, Google, Microsoft, problem, Visual Studio 2005, Visual Studion 2008, vs2005, vs2008
- How-to: Viewing current Route in ASP.NET MVC
-
Posted by oVan on Friday, December 21, 2007 | PermaLink | 1 comments
For those who are playing with the ASP.NET MVC CTP bits, here's an easy way to check the routing info that was used to arrive at your View. You need to enter this into your Site.Master shared view, put it just below the menu-div.
<div class="debug">
<dl>
<dt>Current routing url:</dt>
<dd><%= ViewContext.RouteData.Route.Url.ToString()%>
</dd>
<dt> Current routing values:</dt>
<dd>
<ol><%= ViewContext.RouteData.Values.ToFormattedList("<li>{0}</li>") %></ol>
</dd>
</dl>
</div>
- Download SQL Server Compact 3.5 and Sync for ADO.NET 1.0
-
Posted by oVan on Tuesday, November 27, 2007 | PermaLink | 0 comments
Microsoft made available the Microsoft SQL Server Compact 3.5 and Microsoft Synchronization Services for ADO.Net v1.0 for Windows Desktop package on their download site.
SQL Server Compact 3.5 includes a host of new features including the following:
- LINQ to SQL enabling developers to integrate data access directly into their code
- Side-by-side installation together with SQL Server 2005 Compact Edition (version 3.1)
- Support for newer and more secure encryption algorithms
- Additional timestamp (rowversion) data type
- Enhanced support for Transact-SQL statements including:
- Nested query in FROM clause
- CROSS APPLY and OUTER APPLY
- CAST and DECIMAL
- SET IDENTITY INSERT
- TOP
- Synchronization Services for ADO.NET providing the ability to synchronize data from disparate sources over two-tier, N-tier, and service-based architectures
- Support for System.Transactions
More information:
- SQL Server Compact 3.5 Books Online
- Synchronization Services for ADO.Net Books Online
- For tips and tricks visit Steve Lasker blog, Synchronization Services for ADO.Net blog and SQL Server Compact blog
- For replicating data between SQL Server Compact 3.5 or SQL Server 2005 Compact Edition and SQL Server 2005 (or later versions of SQL Server 2005) install SQL Server Compact 3.5 Server Tools on the IIS server
- Microsoft Visual Studio 2008 installs SQL Server Compact 3.5 and Synchronization Services for ADO.Net by default. If you have already installed Visual Studio 2008 than you don't need to separately download and install SQL Server Compact 3.5
- .NET Framework 3.5 Poster
-
Posted by oVan on Friday, November 23, 2007 | PermaLink | 0 comments
Here's a poster with the Microsoft .NET Framework 3.5 Commonly Used Types and Namespaces.
It contains most used items from LINQ, AJAX, REST, CardSpace, WPF, WF, WCF, CLR, WinForms, Web Services and ASP.NET. There are also visual keys for new items in .NET 3.5, .NET 3.0, Compact Framework 3.5 and planned implementations for Silverlight 1.1.
Download page with 3 formats of the poster
- Visual Studio 2008 and .NET 3.5 are here!
-
Posted by oVan on Monday, November 19, 2007 | PermaLink | 0 comments
The Wait for Visual Studio 2008 is Over!
On Monday, Nov. 19, Microsoft announced that Visual Studio 2008 and the .NET Framework 3.5 were released to manufacturing (RTM). With more than 250 new features,Visual Studio 2008 includes significant enhancements in every edition, including Visual Studio Express and Visual Studio Team System. Developers of all levels – from hobbyists to enterprise development teams – now have a consistent, secure and reliable solution for developing applications for the latest platforms: the Web, Windows Vista, Windows Server 2008, the 2007 Office system, and beyond.
- MSDN Subscribers: Get Visual Studio 2008 Now
- Download Trial Editions of Visual Studio 2008
- Download Visual Studio 2008 Express Editions
- Download the .NET Framework 3.5
Labels: .NET, asp.net, C#, free, Microsoft, MSDN, Visual Studio Orcas, web develoment, Windows
- Free screen capture tool: Cropper
-
Posted by oVan on Saturday, March 24, 2007 | PermaLink | 0 commentsA little known free screen capturing tool is Windows itself: push the PrtScn (the good ol' Print Screen button) and you have an instant copy of your entire desktop. Using Alt+PrtScn you'll get only the active window. This method works in all Windows versions since Windows 95 if I recall correctly.
However, this method is not so practical for a lot of people. If you want to use your screen grab in an email, you can only paste it via Outlook, not via Outlook Express. In that case you need to open MS Paint, or Paint Shop Pro, and paste it there as a new image, then save it as a jpeg, and then go back to your email to attach it as a file. Yuck.
Here's a powerful free screen capture tool called Cropper. The latest release also works on Windows Vista, and it contains screen capture capabilities to:- BMP format
- PNG format
- JPG format
- clipboard (of course)
- directly to printer
- Cropper.AnimatedGif
- Cropper.AviFormat
- Cropper.CountdownPng
- Cropper.SendToEmail
- Cropper.SendToFlickr
- Cropper.SendToOneNote
- Cropper.SendToTinyPic
ps: Cropper is written in C# on the Microsoft .NET platform.Labels: .NET, Avi, C#, CodePlex, Cropper, download, Email, Flickr, free, OneNote, plugin, Png, screen capture, TinyPic

