TempData is available only for a user’s session, so it persists only till we have read it and gets cleared at the end of an HTTP Request. A scenario that fits the usage of TempData, is when data needs to persist between two requests – a redirect scenario. You can use method Keep to store until next request
TempData.Keep
http://msdn.microsoft.com/en-us/library/ee703497.aspx
To fill data from controller, create action:
public ActionResult GetData()
{
// get data from your data source, replace with db call or where to get data
var data = new [] {"sample1", "sample2"};
return Json(data, JsonRequestBehavior.AllowGet);
}
on client when you need data:
$.getJSON(@Url.Action("GetData"), function(data) {
// fill dropdown instead alert
alert(data);
});
See more:
AJAX request aspnet
similar question but for post