I'm building a SMS system. I've contacts and want to allow the user to select multiple contacts and send message to them.
I want to maintain a user's selection of contacts temporarily so that when the user hits SEND button i can process that list.
I'm using C# MVC4 with Ajax calls to code behind method to create either a TempData or Session variable. The problem is, after setting the TempData and Session variable i want to display this data on the screen, but both TempData and Session Variable are empty. As a test i'm just saving "ok" in Session Test Variable. If you have a better idea that will serve the same purpose it'll be grate too.
Thanx
//Javascript function residing on the View
function addToSendList(id) {
$.ajax({
type: "POST",
url: "AddToSendList",
contentType: "application/json;chartset=utf-8",
dataType: "json",
data: "{'id':'" + id + "'}",
success: function (data) {
alert(@Session["test"]);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
//Method on Controller that is called
public JsonResult AddToSendList(string id)
{
int cid = int.Parse(id);
List<Contact> contacts = (from c in db.Contacts
where c.Id==int.Parse(id)
select c).ToList();
Session["test"] = "ok";
return Json(contacts, JsonRequestBehavior.AllowGet);
}
EDIT sorry i made a mistake, i'm sending back the contact to be added into a list by ajax. That is where i'm having problem. How do i maintain that user selected list?