asp.net-mvc – 你可以更新部分视图而不是全页信息吗?

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 你可以更新部分视图而不是全页信息吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法在asp.net mvc中提交部分视图表,而不重新加载父页面,但是将部分视图重新加载到新状态?类似于knockout.js如何更新使用数据绑定。

我的数据表呈现一个可变数量的列/名称,所以我不认为knockout.js是这个选项,所以我试图使用部分视图。

解决方法

不是没有jQuery。

你要做的是把你的部分放在一个div,像:

  1. <div id="partial">
  2. @Html.Partial("YourPartial")
  3. </div>

然后,要更新(例如使用id按钮单击一个按钮),您可以执行以下操作:

  1. $("#button").click(function () {
  2. $.ajax({
  3. url: "YourController/GetData",type: "get",data: $("form").serialize(),//if you need to post Model data,use this
  4. success: function (result) {
  5. $("#partial").html(result);
  6. }
  7. });
  8. }

那么你的行动看起来就像:

  1. public ActionResult GetData(YourModel model) //that's if you need the model
  2. {
  3. //do whatever
  4.  
  5. return View(model);
  6. }

猜你在找的asp.Net相关文章