Getting data back from database after an ajax post submit

Posted by sslepian on Stack Overflow See other posts from Stack Overflow or by sslepian
Published on 2010-03-13T19:25:12Z Indexed on 2010/03/13 19:35 UTC
Read the original article Hit count: 346

Filed under:
|

I've got a web page where the user can add a new item to a category and that item is saved to the database. However, the ID of the item is an identity value for the database table, so I don't know what the ID will be, and I need this ID so that the user can edit the item later.

I'm using ajax to make a POST submit:

$.ajax({
    url: 'TumourGroup/CreateSub',
    type: "POST",
    data: {'pos': index, 'text': text }
});

This is linked to an MVC model with three fields, ID, pos, and text. Is there a way for me to get the ID that's generated on POST submit by having CreateSub(int index, string text) return something?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about jquery-ajax