I am trying to build a post method in a web api using c# on asp.net mvc 4.Whenever I post value to this api using fiddler I get the following error:SqlDateTime溢出。必須是1753年1月1日12:00:00 AM和12/31/9999下午11:59:59在網頁API之間
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
I have written the following code in my web API controller.I have also created the data access layer to access the data in database
public HttpResponseMessage PostMsg(MsgModel item)
{
if (ModelState.IsValid && item!=null)
{
using (dc = new MsgDataContext())
{
var dbMsg = new Msg()
{
Msg_Title= item.Msg_Title,
Msg_Date = item.Msg_Date,
};
dc.Msgs.InsertOnSubmit(dbMsg);
dc.SubmitChanges();// Getting the above error at this line of code
var response = Request.CreateResponse<MsgModel>(HttpStatusCode.Created, item);
string uri = Url.Link("DefaultApi", new { id = dbMsg.Msg_Id});
response.Headers.Location = new Uri(uri);
return response;
}
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
I am posting the following request body from fiddler by executing the
url http://localhost:65070/api/signup Request Body {
'Msg_Title':"our first msg", 'Msg_Date':"2012/02/23T00:00:00"}
調試你的方法我猜'item.Msg_Date'是DateTime.Min。或者你在'Msg'上有一些額外的日期時間字段,你不填寫。 – nemesv 2013-03-25 11:50:31