2012-04-16 5 views
0

항목을 선택하면보기 및 편집을 위해 항목 정보가 텍스트 상자에 표시되는 목록을 생성하는 데 사용되는 ViewData가 있습니다. 저장 버튼을 클릭하면 저장되지만 목록 상자는 업데이트되지 않습니다. 뷰 목록을 사용하고 있으므로이 목록 상자를 어떻게 업데이트 할 수 있습니까? 클릭 저장 버튼시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))"> 

: (자바 스크립트)

 function SaveEpicInfo(name, time, description) { 
    $.get('@Url.Action("SaveEditEpic", "Estimate")', { id: eid, epicname: name, epictime: time, epicdescription: description }, function (result) { 
     alert(result); 

    }); 

} 

컨트롤러 : 당신은 그 선택 배열을 통해 반복하고 선택과 옵션에보고해야 할 것

 [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"); 
     } 
    } 

답변

1

= true로 설정하고 그 값을 저장하십시오.

+0

오른쪽.하지만 어떻게 접근해야합니까? 어떻게 select 배열을 호출 할 것인가? 다른 자바 스크립트에서 나는 $ ("ListBoxClass") 같은 것을 가지고 있었다. (function (event) { var selectedid = $ (this) .find ("option : selected"). 값을 지정한다 – TMan

+0

선택 목록에 ID를 설정한다. 이것은 DOM의 ''요소를 선택하고'.options [] '