使用 Ajax 仅加载或刷新部分视图
我有一个视图,我在其中加载了部分视图,我想刷新视图上的一个 div,而不加载整个视图。我的代码:
@* @Html.Action("MusicPlayer", "NewRelease")*@
`@Html.Partial("_MusicPlayer")`
`@using (Ajax.BeginForm("Index", new AjaxOptions { `
`hereHttpMethod="GET",`
` InsertionMode = InsertionMode.Replace,
UpdateTargetId = "albumlist"
}))
{
<div id="newrealeaseformcontent">
<h2>New Releases(@Model.Genre)</h2>
<div id="daterangesearchcntrl">
@Html.HiddenFor(m => m.Genre)
@Html.Label("choose release date")
@Html.TextBoxFor(m => m.DateRange, new { @readonly = "readonly", @id = "daterange" })
<input class="sb_search" type="submit" value=""/>
</div>
<br />
<br />
<br />
<div id="albumlist">
<ul id="newreleasealbum-list">
@foreach (var album in Model.Albums)
{
<li style="margin-left:0px;padding-left:0px">
<a href="@Url.Action("AlbumPopup", new { id = album.AlbumId })" class="openPlayer">
<img alt="@album.Title" width="75" height="74" src="@album.AlbumPhoto.ThumbnailPath" />
<div class="clear"></div>
</a>
</li>
}
</ul>
<div class="clear"></div>
</div>
</div>
}
</div> `
我想刷新“albumlist”div,而不在此视图上重新加载 Html.Partial("_MusicPlayer")。请帮忙。
提前致谢
I have a view which i load a partial view within it, I want to refresh one div on the view without loading the whole view. my code:
<div id="newrealeaseform">
<div id="newrealeaseformplayer">
@* @Html.Action("MusicPlayer", "NewRelease")*@
</div>
`@Html.Partial("_MusicPlayer")`
`@using (Ajax.BeginForm("Index", new AjaxOptions { `
`hereHttpMethod="GET",`
` InsertionMode = InsertionMode.Replace,
UpdateTargetId = "albumlist"
}))
{
<div id="newrealeaseformcontent">
<h2>New Releases(@Model.Genre)</h2>
<div id="daterangesearchcntrl">
@Html.HiddenFor(m => m.Genre)
@Html.Label("choose release date")
@Html.TextBoxFor(m => m.DateRange, new { @readonly = "readonly", @id = "daterange" })
<input class="sb_search" type="submit" value=""/>
</div>
<br />
<br />
<br />
<div id="albumlist">
<ul id="newreleasealbum-list">
@foreach (var album in Model.Albums)
{
<li style="margin-left:0px;padding-left:0px">
<a href="@Url.Action("AlbumPopup", new { id = album.AlbumId })" class="openPlayer">
<img alt="@album.Title" width="75" height="74" src="@album.AlbumPhoto.ThumbnailPath" />
<div class="clear"></div>
</a>
</li>
}
</ul>
<div class="clear"></div>
</div>
</div>
}
</div> `
I want to refresh the "albumlist" div without reloading the Html.Partial("_MusicPlayer") on this view. Please help.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码不是精确的解决方案,只是一个想法
,这里是你的模型,就像
这里是你的控制器
这是你的视图
这里我使用jquery ajax从服务器获取最新的电影列表。希望它会有所帮助。
The following code is not exact solution just an idea
here is your model as like
Here is your controller
Here is your view
Here i use jquery ajax to get the latest movie list from server. Hope it will help.