ajaxを使用してMVCのテーブルを更新したいとします。私はすでにajaxを使ってデータベースにデータを挿入しました。私は、新しい行を挿入した後にテーブルを更新したいだけです。ASP.NET MVCでAJAXを使用してテーブルをリフレッシュ
PS。私は検索を試みたが、何も助けなかった、私はまだ混乱している。
Here is my code:
Main page View:
<div id="theTable">
@Html.Partial("_IPTable")
</div>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/Admin.js"></script>"`
Partial page View:
<table id="table">`
<tr>
<th>ID</th>
<th>Line</th>
<th>Supplier</th>
</tr>
@foreach (var item in ViewBag.IPTable)`
{
<tr>
<td>
@item.ID
</td>
<td>
@item.Line
</td>
<td>
@item.Supplier
</td>
</tr>
}
</table>enter code here
Controller view:
public ActionResult Admin()
{
// get data from database
return View();
}
public ActionResult _IPTable()
{
return PartialView();
}
挿入新しいレコードのためのAjaxコード:
<script>
$(document).ready(function() {
//function will be called on button click having id btnsave
$("#btnSave").click(function() {
$.ajax(
{
type: "POST", //HTTP POST Method
url: "AdminInsert", // Controller/View
data: { //Passing data
//Reading text box values using Jquery
Line: $("#txtLine").val(),
Supplier: $("#txtSupplier").val()
}
});
});
}); </script>
ajax経由で新しい行を挿入するコードはどこですか? – Shyju
クライアント側のコードは意味しました。 – Shyju
私はそれを下に掲載しました。 –