Reputation: 4122
I have a ViewData that is being used to generate a List, upon selecting an item, that items info will be displayed in textboxes for viewing and editing. Upon clicking the save button, it saves but the listbox isn't being updated, how can update this listbox since I'm using a viewdata?
@Html.ListBox("ListBoxName", new SelectList((IEnumerable<Epic>)ViewData["selectedestimate"], "Id", "Name", "EstimatedTime"), new {@class = "ListBoxClass", @style = "height: 325px;"})
<button id="EpicSaveId" type="submit" class="btn" onclick="SaveEpicInfo((document.getElementById('EpicNameID').value), (document.getElementById('EpicTimeId').value), (document.getElementById('EpicDescriptionID').value))">
Upon Clicking Save Button: (Javascript)
function SaveEpicInfo(name, time, description) {
$.get('@Url.Action("SaveEditEpic", "Estimate")', { id: eid, epicname: name, epictime: time, epicdescription: description }, function (result) {
alert(result);
});
}
Controller:
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult SaveEditEpic(int id, string epicname, double epictime, string epicdescription)
{
var epic = epicRepository.Select().SingleOrDefault(x => x.Id.Equals(id));
if (epic != null)
{
epic.Name = epicname;
epic.EstimatedTime = epictime;
epic.EpicDescription = epicdescription;
//ViewData["selectedestimate"] = epicRepository.Select().Where(x => x.EstimateId.Equals(ActiveEstimateId)).ToList();
return Json("Epic Saved", JsonRequestBehavior.AllowGet);
}
else
{
return Json("Error");
}
}
Upvotes: 0
Views: 401
Reputation: 82287
You are going to have to iterate through those select arrays and look for the option with selected = true and then store that value.
Upvotes: 1