ASP.net MVC3 Date Formats validation Issued (dd/mm/yyyy vs mm/dd/yyyy)
Client side passing date format as "dd/mm/yyyy" format. but model is return format is incorrect its cheeking mm/dd/yyyy. i have found that issue in mvc web application.
solution
Reason is that web server culture info is used as "en-us" its validate format "mm/dd/yyyy". then i found that we can change the culture dynamically in the following way .
Option 1: Page level
The Culture used by the individual Page can be set via theCulture
property.
<%@ Page Culture="en-SG" Language="C#" %>Option 2: Application wide (web.Config)
The Culture can be set Application wide by adding thenode to the
web.Config
file. Thenode must be placed inside
.
<system.web><globalization culture="en-SG"/>Option 3: Thread level
The Culture of the current Thread can be changed programatically be setting theSystem.Threading.Thread.CurrentThread.CurrentCulture
property.
The following example demonstrates how to get the user-agent(browsers) preferredUserLanguage
property on each Request and set the ThreadsCurrentCulture
during theApplication_BeginRequest
Event.
protected void Application_BeginRequest(Object sender, EventArgs e){CultureInfo requestCulture;
try
{
requestCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
}catch
{// Return server Culture if none available in HttpHeaders.
requestCulture = CultureInfo.CurrentCulture;
}System.Threading.Thread.CurrentThread.CurrentCulture = requestCulture;
}
No comments:
Post a Comment