Set culture, UI culture in <Globalization /> section in web.config file to work on same datetime format both on local as well as production environment.
I was setting my bootstrap calendar to get datetime in "dd/mm/yyyy" format. It was working fine on my local machine. Format was showing correctly and I was able to search records as it should be. But as I moved to production environment, it started creating problem. First of all if I was taking date as say "20th Oct, 2015", it was throwing datetime conversion error (Out of bound). I debugged my code and found that Datetime was not in correct format.
First of all let's see the code. I had created a MVC application. Below is my jquery code which is calling my MVC action.
function SearchBox() {
var f = $("#fromDate").val();
var t = $("#toDate").val();
$.ajax({
type: 'POST',
url: "/Home/Search/",
data: { fromDate:f, toDate:t },
success: function (result) {
$("#dvres").html(result);
},
error: function (ex) {
alert('Facing error while processing your request. Please try later.' + ex)
}
});
}
[HttpPost]
public JsonResult Search(DateTime fromDate, DateTime toDate)
{
var model = search.SearchResult(fromDate, toDate);
return Json(new { Data = model}, JsonRequestBehavior.AllowGet);
}
DateTime parameter was not converting date correctly.
The problem was with application culture. Set culture info in web.config file in
To make it working, I simply added
<system.web>
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-GB"
uiCulture="en-GB" />
</system.web>
It was a small trick or say mistake. Hope it should you.