Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My Model:
public partial class WorkTime
{
public int WorkTimeId { get; set; }
public int CalendarId { get; set; }
public string DayName { get; set; }
public System.DateTime FromTime { get; set; }
public System.DateTime ToTime { get; set; }
public int DurationBreak { get; set; }
public bool IsEnabled { get; set; }

public virtual Calendar Calendar { get; set; }
}

Index.cshtml:

var start = $("#FromTime").kendoTimePicker({
change: startChange,
type: "string",
format: "HH:mm tt",
parseFormats: ["HH:mm"],
value:kendo.stringify(this.value),
});
var end = $("#ToTime").kendoTimePicker({
type: 'string',
format: "datetime",
parseFormats: ["HH:mm"],
}).data("kendoTimePicker");

Controller:



public JsonResult Create(WorkTime worktime)
{
if (ModelState.IsValid)
{
try
{
db.WorkTimes.Add(worktime);
db.SaveChanges();
return Json(worktime, JsonRequestBehavior.AllowGet);
}
}
catch (Exception e)
{
return
Json(
HelperModel.GenerateErrorMessage(null,
"There is a problem while saving the created record. Please try again!"),
JsonRequestBehavior.AllowGet);
}

}
return Json(HelperModel.GenerateErrorMessage(ModelState), JsonRequestBehavior.AllowGet);
}




I want to save time to my problem is worktime.Fromtime always return {1/1/0001 12:00:00 AM}? anyone help me?
Posted

1 solution

Please don't post question after question on the same thing. Just edit your question so that it's got the detail we need.

Have you set breakpoints in your page in Chrome to see what value you're getting from the control and what you're passing to the AJAX call ? Have you set breakpoints in your code to see what's being passed from the server ? First step is to work out which part is failing.

I don't see the code where you make the AJAX call.

And the fact you're passing in your own class, is a big warning sign. What else is in a 'WorkTime' ? How are you sure that you're constructing a valid instance in JSON ? I don't think you are, that's why you're getting a default value, because the compiler creates one for you. That's almost certainly what is broken. Don't be cute. Pass in the values and construct your object on the server.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900