在更新ASP.NET MVC C#与jQuery局部视图 [英] Updating partial view with Jquery in ASP.NET MVC C#

查看:173
本文介绍了在更新ASP.NET MVC C#与jQuery局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC C#和jQuery一起。

I am using MVC C# along with Jquery.

我在有多个选项卡一个相当大的页面的局部视图。

I have a partial view in a rather large page that has a number of tabs.

在复选框的点击,我喜欢更新中的形式局部视图。
我所获得,而不是仅仅是局部视图

On a click of a checkbox, I like to update the partial view WITHIN the form. What I am getting instead is just the partial view

下面是我的code jQuery中:

Here is my code in Jquery:

   $('#activelist,#inactivelist').change(function () {

        var status = 'inactive';
        window.location.href = '@Url.Action("Skits","KitSection")' + '?id=' + id+ '&status=' + status;

    });

这是我怎么能更新的我将如何对其进行的呼叫而言表单中的局部视图任何想法?

Any idea on how I could update the partial view within a form in terms of how I would make a call to it?

下面是code为PartialView

Here is the code for the PartialView

     return PartialView(Kits);

正如前面提到的,我看到的只是局部视图中显示,而不是整个表格。

As mentioned, what I see is just the partial view displayed and not the whole form.

推荐答案

window.location.href 将刷新整个页面。你需要重新载入网页的某些部分没有一个完整的重新加载。我们可以使用jQuery Ajax来做到这一点。让我们来看看什么jQuery选择,您可以使用来获取Partialview。

window.location.href will reload the entire page. You need to reload some part of your page without a complete reload. We can use jQuery ajax to do this. Let's Find out what jQuery selector you can use to get the Partialview.

例如,假设你的HTML标记就是这样在主窗体(视图)

For example , Assume your HTML markup is like this in the main form ( view)

<div>
  <p>Some content</p>
  <div id="myPartialViewContainer">
      @Html.Partial("_FeaturedProduct")
  </div>
  <div>Some other content</div>
</div>

和这里的 DIV ID myPartialViewContainer 是容器div持有的局部视图。所以,我们将只需重新加载的,内容的div使用jQuery的负荷方法

And here the DIV with ID myPartialViewContainer is the Container div which holds the content of the partial view.So we will simply reload the content of that div using jQuery load method

$(function(){

   $('#activelist,#inactivelist').change(function () {
      var id="someval"; 
      var status = 'inactive';
      $("#myPartialViewContainer").load('@Url.Action("Skits","KitSection")' + '?id=' + id+ '&status=' + status)
  });

});

这篇关于在更新ASP.NET MVC C#与jQuery局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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