On my button click i am passing model to the controller with datetime objects in that in my local database it is working fine but when i upload to server the datetime value is taking null.how to resolve this problem. this is my code for button click
$('#btnTaxiCall').on('click', function () {
stopCallTime();
var TaxiCallTime = new Date();
//alert(TaxiCallTime.toUTCString());
// $('#TaxiCallTime').val(TaxiCallTime.toISOString());
$('#TaxiCallTime').val($.date(TaxiCallTime));
var model = $("#formTaxiLog").serializeArray();
$('#btnTaxiArrival').removeAttr('disabled');
$.ajax({
url: '/TaxiLog/Add', type: 'Post', dataType: 'json',
data: $.param(model),
success: function (data) { $('#btnTaxiCall').css({ backgroundColor: 'green' }); isSaved = true; Id = data.id; $('#CallTime button').attr('disabled', 'disabled'); $('#ErrMsg').hide(); $('#CallTime div').removeClass('customValidation'); $("#Id").val(Id); }
});
$.date = function (dateObject) {
// alert(dateObject);
var d = new Date(dateObject);
var day = d.getDate();
var month = d.getMonth();
var year = d.getFullYear();
var hours = d.getHours();
var minutes = d.getMinutes();
var seconds = d.getSeconds()
var date = day + "/" + month + "/" + year + " " + hours + ((minutes < 10) ? ":0" : ":") + minutes + ((seconds < 10) ? ":0" : ":") + seconds;
return date;
}
public int Post(TaxiLogVM vm)
{
using (var dc = new SGSDBContext())
{
string sql = "SELECT COUNT(Id) FROM [dbo].[Venue] WHERE [Id]={0};";
if (dc.Database.SqlQuery<int>(sql, vm.VenueId).FirstOrDefault() == 0)
{
return 0;
}
else
{
vm.CreatedDate = vm.ModifiedDate = DateTime.Now;
//vm.TaxiArrivalTime = null;
sql = "INSERT INTO [dbo].[TaxiLog]([VenueId],[UserId],[Title],[Name],[Destination],[TaxiFirmId],[TaxiCallTime],[TaxiArrivalTime],[CreatedDate],[ModifiedDate]) "
+ "VALUES({0},{1},{2},{3},{4},{5},{6},{7},{8},{9}); "
+ "SELECT SCOPE_IDENTITY();";
vm.Id = (int)dc.Database.SqlQuery<decimal>(sql, vm.VenueId, vm.UserId, vm.Title, vm.Name, vm.Destination, vm.TaxiFirmId, vm.TaxiCallTime.Value.ToString(" hh:mm:ss tt"), SqlDateTime.Null, vm.CreatedDate, vm.ModifiedDate).FirstOrDefault();
dc.SaveChanges();
return vm.Id;
}
}
}