我想使用ajax更新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();
}
Run Code Online (Sandbox Code Playgroud)
用于插入新记录的Ajax代码:
<script>
$(document).ready(function () {
//function will be called on button …Run Code Online (Sandbox Code Playgroud)