2016-04-20 8 views
1

私はwebgridをユーザが編集してインラインで削除できるようにしようとしているので、webgridにして、それを正常にバインドして、更新機能を働かせます。編集ボタンのラベルをテキストとドロップダウンリストに変換します。コードどのように私はasp MVCのドロップダウンリストの値のテキストをキャッチすることができますか?

<script type="text/javascript"> 
$(function() { 
    $('.edit-mode').hide(); 
    $('.edit-user, .cancel-user').on('click', function() { 
     var tr = $(this).parents('tr:first'); 


     tr.find('.edit-mode, .display-mode').toggle(); 
    }); 
    $('.save-user').on('click', function() { 
     var getValue; 
     var tr = $(this).parents('tr:first'); 
     var FirstName = tr.find("#FirstName").val(); 
     var Phone = tr.find("#Phone").val(); 
     var Branch = tr.find("#Branch-drop").val(); 

     getValue = $("#Branch-drop option:selected").text(); 

     var UserID = tr.find("#UserID").html(); 
     tr.find("#lblFirstName").text(FirstName); 
     tr.find("#lblPhone").text(Phone); 
     tr.find("#lblBracnh").text(getValue); 
     tr.find('.edit-mode, .display-mode').toggle(); 
     var UserModel = { 
      "IdEmp": UserID, 
      "EmpName": FirstName, 
      "Phone": Phone, 
      "BranchName": Branch 
     }; 
     $.ajax({ 
      url: '/Home/UpdateUser/', 
      data: JSON.stringify(UserModel), 
      type: 'POST', 
      contentType: 'application/json; charset=utf-8', 
      success: function (data) { 
       alert(data); 

      } 
     }); 
    }); 
}) 




    </script> 

とWebGridのコードが

  @{ 
     var grid = new WebGrid(Model); 
     } 


    <div id="gridContent" style=" padding:20px; "> 
     @grid.GetHtml(
    tableStyle: "webgrid-table", 
    headerStyle: "webgrid-header", 
    footerStyle: "webgrid-footer", 
    alternatingRowStyle: "webgrid-alternating-row", 
    selectedRowStyle: "webgrid-selected-row", 
    rowStyle: "webgrid-row-style", 
    mode: WebGridPagerModes.All, 
    columns: 
     grid.Columns(
      grid.Column("IdEmp", "ID", format: @<text> <span class="display-mode">@item.IdEmp </span> <label id="UserID" class="edit-mode">@item.IdEmp</label> </text>, style: "col1Width"), 
     grid.Column("EmpName","Employee Name", format: @<text> <span class="display-mode"> <label id="lblFirstName">@item.EmpName</label> </span> <input type="text" id="FirstName" value="@item.EmpName" class="edit-mode" /></text>, style: "col2Width"), 
     grid.Column("Phone", "Phone", format: @<text> <span class="display-mode"> <label id="lblPhone">@item.Phone</label> </span> <input type="text" id="Phone" value="@item.Phone" class="edit-mode" /> </text>, style: "col2Width"), 
     grid.Column("BranchName","Branches", format: @<text><span class="display-mode"> <label id="lblBracnh">@item.BranchName</label> </span> @Html.DropDownList("MyDropdowen", (SelectList)ViewBag.DropDowenValue, new { id = "Branch-drop", @class = "edit-mode" })</text>,style:"col2Width"), 
     grid.Column("Action", format: @<text> 
    <button class="edit-user display-mode">Edit</button> 
    <button class="save-user edit-mode">Save</button> 
    <button class="cancel-user edit-mode">Cancel</button> 
    <button class="Delete-user ">Delete</button> 
     </text>, style: "col3Width", canSort: false) 
         )) 

ある問題が表示されますが、現在の値と、私はそれを変更するには、テキストラベルドン」に表示されていない場合にドロップダウンリストであります〜を取る新しい値だから私はドロップダウンリストを現在の値にすることができます。ユーザーが新しいテキストを選択して押したときにドロップダウンを保存すると、新しい値を取ることができますか?

+0

あなたの "ViewBag.DropDowenValue"が空であるかどうかを確認してください。 –

+0

いいえ空ではありません。リストを返します。 –

答えて

1

DropDownListコントロールここ のGET値テキストの構文に誤りが私のコードがあります:

getValue = $("#Branch-drop option:selected").text(); 

は次のようになります。

 getValue = tr.find("#Branch-drop option:selected").text(); 

、それは皆のため 感謝を働いていますあなたがかもしれ

関連する問題