jquery ajax渲染,jquery – 使用Ajax加载图像在MVC 3中渲染部分视图

我刚开始使用

Html.RenderPartial(usercontrol,model)来呈现我的用户控件.在部分视图加载时是否可以更改此功能以显示Ajax加载图像?

编辑:试过这个,但一直无法让它工作.我有这样的局部视图(_FixtureList.cshmtl):

@model List

@foreach (var item in this.Model)

{

@Html.Encode(item.Week) logo@Html.Encode(item.Opponent)@Html.Encode(item.Result)

目前这是我呈现页面的方式:

public ActionResult Cincinnati()

{

//renderpartial

List lstFixtures = _Base.DataRepository.GetFixtureList("2017","Cincinnati");

return View(lstFixtures);

}

}

这是我观点的相关部分(Cincinnati.cshtml):

@model List

@{

ViewBag.Title = "Cincinnati Bengals";

Layout = "~/Areas/Gameplan/Views/Shared/_Layout.cshtml";

}

fixtureweek.jpgfixtureopponent.jpgfixturescore.jpg

@{ Html.RenderPartial("_FixtureList",this.Model); }

我如何将您的示例应用于此代码?

编辑:

想出来,这就是我做到的:

public ActionResult MyPartial()

{

List lstFixtures = _Base.DataRepository.GetFixtureList("2016","Cincinnati");

return PartialView("_FixtureList",lstFixtures);

}

在视图中:

$.ajax(

{

type: 'POST',async: true,contentType: 'application/json; charset=utf-8',dataType: 'html',url: 'MyPartial',beforeSend: function (xhr) {

$('#mydiv').addClass('ajaxRefreshing');

xhr.setRequestHeader('X-Client','jQuery');

},success: function (result) {

$('#mydiv').html("

fixtureweek.jpgfixtureopponent.jpgfixturescore.jpg
");

},error: function (error) {

alert(error);

},complete: function () {

$('#mydiv').removeClass('ajaxRefreshing');

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值