MVC 4阿贾克斯是不是在页面内更新PartialView [英] MVC 4 Ajax is not updating the PartialView within the page

查看:131
本文介绍了MVC 4阿贾克斯是不是在页面内更新PartialView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么用的MVC 4的网站,它是一个网站列出的音乐,用户可以创建播放列表(如购物车购物)。

I'm doing a site using MVC 4. It's a site that list musics and the user can create a playlist (like a cart shopping).

我对每一个音乐应在阿贾克斯执行此操作链接:

I have for every music this action link that should be executed in Ajax:

@Ajax.ActionLink("Adicionar à Playlist","AddPlaylist", new { id = item.MusicaID }, new AjaxOptions {UpdateTargetId="playlist", InsertionMode=InsertionMode.Replace})

从控制器的操作方法返回一个PartialView(播放列表的购物车),并只应该更新,但不是让整个页面与部分更新,我得到的局部视图,并没有更多的页面上。

The action method from the controller returns a PartialView (the cart of playlist) and only that should update but instead of getting the whole page with that part updated I get a partial view and nothing more on the page.

这是我的渲染PartialView部分:

This is the part where I render the PartialView:

<section id="playlist">
     @Html.Partial("_PlaylistPartial")
</section>

应该不是这个工作,像我有?

Shouldn't this work like I have?

推荐答案

这是一个愚蠢的事。

首先我包括jquery.unobtrusive-ajax.min.js没有工作,像我有:

First my include of jquery.unobtrusive-ajax.min.js didn't work like I have:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

所以我把这样的:

So I put like this:

@Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js")

和仍然是行不通的,因为我还需要包括JQuery的文件:

And still wasn't working, because I also need to include the JQuery files:

@Scripts.Render("~/Scripts/jquery-1.7.1.js")
@Scripts.Render("~/Scripts/jquery.1.7.2.min.js")

此方式,它的工作原理:)

This way it works :)

这篇关于MVC 4阿贾克斯是不是在页面内更新PartialView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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