2012-04-16 28 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))"> 

:(Javascriptの)

 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

そうですが、どうすればそれにアクセスできますか?どのように選択配列を呼び出すのですか?別のJavaScriptで、私は$( "ListBoxClass")のようなものを持っていました。(function(event){ var selectedid = $(this).find( "option:selected")。値は – TMan

+0

選択リストにIDを設定するこれはDOM上の ''要素を選択し、 '.options [] '