您可以只更新部分视图而不是整页帖子吗? [英] Can you just update a partial view instead of full page post?

查看:77
本文介绍了您可以只更新部分视图而不是整页帖子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在asp.net mvc中提交部分视图表单而无需重新加载父页面,而是仅将部分视图重新加载到其新状态?与基因敲除.js使用数据绑定更新的方式类似.

Is there a way to submit a partial view form in asp.net mvc without reloading the parent page, but reloading the partial view only to its new state? Similar to how knockout.js updates using data-bind.

我的数据表呈现的列数/名称数是可变的,因此我不认为kickout.js是该选项,因此我尝试使用部分视图.

My data table renders with a variable number of columns/names so I don't think knockout.js is an option for this one, so I am trying to use a partial view instead.

推荐答案

并非没有jQuery.

Not without jQuery.

您需要做的是将Partial放入div中,例如:

What you would have to do is put your Partial in a div, something like:

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

然后,要进行更新(例如,单击ID为button的按钮),可以执行以下操作:

Then, to update (for example clicking a button with the id button), you could do:

$("#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);
       }
   });
})

然后您的操作将类似于:

Then your action would look something like:

public ActionResult GetData(YourModel model) //that's if you need the model
{
    //do whatever

    return View(model);
}

这篇关于您可以只更新部分视图而不是整页帖子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆