我有一个 MVC3 应用程序,它使用 ViewBag 变量从数据库中动态获取数据并动态生成接口。
我正在使用 jQuery 调用 action 方法将一些值插入数据库并相应地更新 ViewBag 变量。我想用从服务器更新后返回的新 ViewBag 值刷新 div ......真的不知道该怎么做。谢谢
这是我的查看代码:
<div id="phys">
<fieldset>
<legend>IPSS</legend>
@foreach (var parameter in ViewBag.four.Parameters)
{
@MyHelpers.ParameterList(parameter, ViewBag.four.ParametersValues, "ParametersList")
}
<button type="button" onclick="print()" class="t-button">
Add Physician</button>
<table>
<thead>
<th>
Physician
</th>
<th>
Time
</th>
<th>
Delete
</th>
</thead>
<tbody>
@foreach (var row in ViewBag.physicians.ParametersValues)
{
<tr>
@{var items = ((string)row.Value).Split('|');}
<td>@items[0]
</td>
<td>@items[1]
</td>
<td>@Html.ActionLink("Delete", "DeleteVisitParameter", new { vpid = @row.VisitParameterID })</td>
</tr>
}
</tbody>
</table>
</fieldset>
</div>
这是我的 jQuery:
<script type="text/javascript">
$(document).ready(function () {
print = function () {
//$.post("/visit/physicians", { phy: $("#ParamList7 option:selected").text(), vID: '@ViewBag.VisitID' })
$.ajax({
cache: false,
type: "POST",
url: '@Url.Content("~/visit/physicians")',
data: { phy: $("#ParamList7 option:selected").text(), vID: '@ViewBag.VisitID' },
success: function (data) {
//What Shall I do here to update div #phys with new View Data??
},
fail: function (msg) {
alert("Fail"); ;
}
});
};
});
</script>