Pergunta

I used to be able to edit a record, click Save, and the record updates. I had a couple jQuery datepicker's on my form - just standard MM/dd/yyyy format. SQL didn't mind updating the SQL datetime with these. Now, I added a timepicker addon (http://trentrichardson.com/examples/timepicker/). So I go back to the same form, fill out my fields, click Save, and I get the ugly YSOD. The only difference is the format of the data in the fields representing the two dates. What is weird is this only happens on an Edit. A brand new record inserts just fine with the timepicker. Here's the YSOD and my new form fields representing the timepicker - I'm not showing the UI for the timepicker as that's not relevant, what's relevant is the data in the form field that is being passed back to SQL for an update:

enter image description here

enter image description here

I have a WebAPI sitting on a separate server that handles all of the CRUD operations. Any ideas what's going on???

EDIT: Here's my Api POST controller method:

[HttpPut]
        public HttpResponseMessage PutBulletinBoard(int id, BulletinBoard bulletinBoard)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            db.Entry(bulletinBoard).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Foi útil?

Solução

So, I had my Put method on my API controller as follows:

[HttpPut]
        public HttpResponseMessage PutBulletinBoard(int id, BulletinBoard bulletinBoard)
        {

The problem apparently was the name of the PUT method above - it needed to be:

[HttpPut]
        public HttpResponseMessage Put(int id, BulletinBoard bulletinBoard)
        {

Because of some custom WebApiConfig.cs routes. Out of the box, it's named as PutBulletinBoard, but I made some changes to the routing.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top