我们在做MVC 进行某一块的局部刷新,有的使用AJAX 请求,有的使用局部页;

下面我给大家推荐一种使用局部页面实现的这种方式:

第一步:

嵌套视图页

 <div id="showAudit">
@*操作信息*@
@{Html.RenderPartial("ShowAudit", Model);}
</div>

第二步:

编写后台代码

[HttpGet]
public ActionResult ShowAudit(int id)
{
using (var _ctx = new BtDbContext())
{
var memberSupply = _ctx.MemberSupplys.FirstOrDefault(c => c.MemberId == id); MemberSupplyModel model = new MemberSupplyModel(); if (memberSupply != null)
{ model.MemberId = memberSupply.MemberId;
model.OrderNumber = memberSupply.OrderNumber;
model.CardId = memberSupply.CardId;
model.Name = memberSupply.Name;
model.MemberMobile = memberSupply.MemberMobile; model.State = memberSupply.State;
model.CreateTime = memberSupply.CreateTime;
model.UpdateTime = memberSupply.UpdateTime;
model.CompanyName = memberSupply.CompanyName;
model.CompanyAddress = memberSupply.CompanyAddress; model.CompanyPhone = memberSupply.CompanyPhone;
model.CompanyUrl = memberSupply.CompanyUrl;
model.ManagementProduct = memberSupply.ManagementProduct;
model.ContactJob = memberSupply.ContactJob;
model.ContactPeople = memberSupply.ContactPeople; model.ContactMobile = memberSupply.ContactMobile;
model.Memo = memberSupply.Memo;
model.OpEmployeeName = memberSupply.OpEmployeeName;
} return PartialView(model);
}
}

第三步:

编写视图页面:

@using WechatMall.Common.Extensions;

@model WechatMall.Model.ViewModel.MemberSupplyModel

@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@if (Model.State != WechatMall.Common.EnumHelper.MemberApplyForStatus.AuditNot)
{ <table class="ltable" style="margin-top:30px;">
<thead>
<tr>
<th colspan="" style=" text-align:left;padding-left:20px; font-weight:bold; background-color:#ffffff; ">操作信息</th>
</tr>
</thead>
<tbody class="ltbody">
<tr>
<td style="width:18%">@Html.DisplayNameFor(model => model.OpEmployeeName)</td>
<td style="width:18%">
@Html.DisplayFor(modelItem => Model.OpEmployeeName)
</td> <td>@Html.DisplayNameFor(model => model.State)</td>
<td style="width:15%">
@Model.State.ToDescriptionString()
</td> <td>@Html.DisplayNameFor(model => model.UpdateTime)</td>
<td>
@Html.DisplayFor(modelItem => Model.UpdateTime)
</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(model => model.Memo)</td>
<td colspan="">
@Html.DisplayFor(modelItem => Model.Memo)
</td>
</tr>
</tbody>
</table>
}

第四步:

编写JS 代码

    $("#sbmbtn").click(function () {

            $.post('@Url.Action("AuditDispose", "Members")', $("#form1").serialize(), function (json) {

                if (json.f) {
$("#showAudit").load('@Url.Action("ShowAudit", "Members", new { id = Model.MemberId }, Request.Url.Scheme)')
}
else {
alert(json.ext);
}
}); });

这样就可以轻松搞定了;推荐一下参考网址:https://cmatskas.com/update-an-mvc-partial-view-with-ajax/

那有里有不对的地方希望大家指出来,或者有更好的方法提出来,大家相互学习,进步..

最新文章

  1. Grunt 使用记录
  2. GCC的gcc和g++区别
  3. IDE:Eclipse查看接口实现类快捷键
  4. DataTable使用技巧总结【转】
  5. 有关JVM内存
  6. HadoopDoctor:来自腾讯数据仓库TDW的MR诊断系统
  7. 从零开始学JAVA(03)-用Eclipse生成HelloWorld的Jar文件(简单不带包)
  8. NgNice项目案例
  9. win7问题解决,凭据管理器和无法访问,不允许一个用户使用一个以上用户名与服务器或共享资源进行多重连接。
  10. C++负数取模
  11. 【尚学堂&#183;Hadoop学习】MapReduce案例1--天气
  12. String类,StringBuffer类转字符数组
  13. canvas图片与img图片的相互转换
  14. Finance财务软件帮助
  15. 你知道Java的四种引用类型吗
  16. Python迭代器与格式化
  17. python jquery初识
  18. Codeforces Round #545 (Div. 2)(D. Camp Schedule)
  19. tmux用于恢复远程屏幕
  20. 【BestCoder】【Round#42】

热门文章

  1. form表单 无法提交js动态添加的表单元素问题。。
  2. c++回调
  3. 要在一般处理程序中获取其他页面的session值
  4. maven auto-config 多环境自动打包
  5. hdu2099
  6. AJAX验证用户是否存在
  7. 实现IHttpModule接口,给每个页面输出一段脚本
  8. 【风马一族_php】NO1_用php发出一声 Hi
  9. java项目编译有误
  10. CentOS 6破解Mysql5.5的办法