Query String Culture vs. Form Culture

Story Zero.

There are Culture and UICulture principles in .NET. Culture is reponsible for date, time, number, calendars and so on. It requires to have both a language and a region. UICulture is responsible for resources, string and labels on your UI (whatever it might be, a web from, a windows form or a xaml layout). It can be region-agnostic.

Story One.

DateTime relies tightly on a culture (Culture). Any number relies on a culture. Do you know anything else? They relies when you want to see their string representation or pull in from the representation. It is not a big secret for a developer.

Story Two.

An html form can be passed back to a web application using GET or POST. When you are GET, you are a part of address, when you are POST you are a part of body. The best way to distinguish them is to use REST philosophy. If you change something than you are posting, if you read something than you are getting. Trivial.

Story Three.

The thrid story was not obvious for me at the first glance. ASP .NET MVC framework is powerful and flexible. It can simply pass POST (from a body) and GET (from a query string) data into parameters of methods. And these parameters can be of a simple type as well as of a complex-n-custom one. The IModelBinder is behind the scene. Assume that we use the DefaultModelBinder out of the box and answer such question. When you are passing a string representation of DateTime with GET, what culture will be used (Culture / UICulture)? Done? Then what will happen if you POST the data (who cares Culture / UICulture)?


The invariant culture will be used for the first case. And the Culture will be used for the second one. I have not told you about the invariant culture. The invariant culture is language and region agnostic. It exists on any .NET platform and it is the same everywhere. It is most likely to use when you store settings and read them. So could you answer a question why do MVC use this culture for a query string? I thought and found the simple answer – because a URI address is culture-less. You should be able send your URI to any from all over the world and the man should be fine opening an exact source and state you are looking for.

Be aware: when you are passing data through a query string – you are in invariant culture!

This entry was posted in .NET, ASP .NET MVC. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s