2017-12-18 23 views
0

にカミソリビューでdiv要素をリロードする方法これは、カミソリでの私のコードは、基本的にデータベースから情報を抽出することで、テーブルを表示することを表示している -は、モデルの値を更新し、MVC

@model List<EmpoyeeInfo.Models.FFX_HR_Employees> 
@using System.Reflection; 

@{ 
    ViewBag.Title = "Employee Information"; 
    var Properties = Model[0].GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList(); 
    string[] head = new string[Properties.Count()]; 
} 

<div id="web-top"> 

    <div id="horizontal-line"></div> 
    <input class="search-box-text" type="text" spellcheck="false" placeholder="Search Individual Record..." title="Search Individual Record" id="searchbox" name="searchbox" /> 

</div> 

<div id="web-main"> 
    <table class="employee-info"> 
     <tr> 
      @foreach (var Property in Properties) 
      { 
       if (Property.Name.Equals("AnnualHolidayEntitlement")) 
       { 
        <th colspan="2">@Property.Name</th> 
       } 
       else 
       { 
        <th>@Property.Name</th> 
       } 
      } 
     </tr> 

     @foreach(var Row in Model) 
     { 
      <tr> 
       @{ 
        Type type = Row.GetType(); 
        IList<PropertyInfo> props = new List<PropertyInfo>(type.GetProperties()); 
       } 
       @foreach (PropertyInfo prop in props) 
       { 
        if (prop.Name.Equals("AnnualHolidayEntitlement")) 
        { 
         <td contenteditable="true">@prop.GetValue(Row, null)</td> 
        } 
        else 
        { 
         <td>@prop.GetValue(Row, null)</td> 
        } 
       } 
       <td class="saveToDB">SAVE</td> 
      </tr> 
     } 
    </table> 
</div> 

をしかし、私は検索で入力すると、ボックスのテキストは、AJAX呼び出しが作られています -

$(document).ready(function() { 
    $('.search-box-text').keypress(function() { 
     getReport($(this).html()); 
    }); 
}) 

function getReport(Name) { 
    $.ajax({ 
     url: '@Url.Action("Index", "Home")', 
     type: 'POST', 
     data: { Name: Name }, 
     dataType: "json", 
     cache: false, 
     success: function (result) { 
      //do stuff; 
     }, 
     error: function() { 
      console.log("no display"); 
     } 
    }); 
} 

は今どのように私はdivのリロードん - 「ウェブメインの」と名のユーザーを検索して、表にもあることが必要であるようなモデル値を更新します更新しました。

答えて

0

以下のコードはdiv 'web-main'に結果を追加します。あなたのコードでjQueryの成功部分を操作する必要があります

$(document).ready(function() { 
      $('.search-box-text').keypress(function() { 
       getReport($(this).html()); 
      }); 
     }) 

     function getReport(Name) { 
      $.ajax({ 
       url: '@Url.Action("Index", "Home")', 
       type: 'POST', 
       data: { Name: Name }, 
       dataType: "json", 
       cache: false, 
       success: function (data) { 
        //do stuff; 
     console.log(data); 
       $("web-main").append(JSON.stringify(data)); 
       }, 
       error: function() { 
       console.log("no display"); 
       } 
      }); 
     } 
+0

私はモデルの値を変更する方法はありますか? のようなもの - @Model = data(スクリプト部分) –

+0

IndexアクションでHomeController内のデータを操作する必要があります。インデックスアクションから値を返すと、HTMLにdivを追加できます – Yasirmx

関連する問題