有没有办法在asp.net mvc中提交部分视图表,而不重新加载父页面,但是将部分视图重新加载到新状态?类似于knockout.js如何更新使用数据绑定。
解决方法
不是没有jQuery。
你要做的是把你的部分放在一个div,像:
- <div id="partial">
- @Html.Partial("YourPartial")
- </div>
然后,要更新(例如使用id按钮单击一个按钮),您可以执行以下操作:
- $("#button").click(function () {
- $.ajax({
- url: "YourController/GetData",type: "get",data: $("form").serialize(),//if you need to post Model data,use this
- success: function (result) {
- $("#partial").html(result);
- }
- });
- }
那么你的行动看起来就像:
- public ActionResult GetData(YourModel model) //that's if you need the model
- {
- //do whatever
- return View(model);
- }