在写mvc项目时,一个列表查询页面含有多个操作按钮及弹框操作。原本写在了一个view中,导致代码繁多复杂,难以维护,还有表单赋值清空、验证等麻烦。

因此改用kendo window +partialView的方式,代码清洁,方便维护。也可以实现复用。

1、当前view中添加kendo window 弹框

@(Html.Kendo().Window()
.Name("partialViewWindow")
.Title(Resources.OrderCheckFreeEquipmentScrap)
.Modal(true)
.Content(@<text>
<div id="partialViewDiv"></div>
</text>)
.Draggable()
.Resizable()
.Width(600)
.Visible(false)
.Actions(actions => actions.Close())
)

2、grid列表操作一行时,弹出操作框

  function agreeDrop(e) {
var dataItem = $("#EquipmentGrid").data("kendoGrid").dataItem($(e).closest("tr"));
var url = "@Url.Action("AgreeDropEquipment", "OrderCheckManage", new { id = "__id__" })";
$("#partialViewDiv").load(url.replace("__id__", dataItem.Id));
$("#partialViewWindow").data("kendoWindow").center().open();
}

3、controller action代码

        [HttpGet]
public ActionResult AgreeDropEquipment(int id)
{ EquipmentDropModel model=new EquipmentDropModel
{
Id = id
};
return PartialView(model);
} [HttpPost]
public ActionResult AgreeDropEquipment(EquipmentDropModel model)
{
try
{
var userId = UserId();
_commonService.ScrapEquipment(model.Id,model.DepreciationYear,model.SalvageValue,model.Comment,userId);
return RedirectToAction("Index", "OrderCheckManage");
}
catch (Exception exp)
{
_commonService.SaveLog(exp.ToString());
throw;
}
}

4、PartialView

@model DMS.WEB.Models.EquipmentDropModel
<form action="@Url.Action("AgreeDropEquipment", "OrderCheckManage")" method="post" class="panel panel-default form-horizontal panel-body">
<div class="form-group">
@Html.HiddenFor(m => m.Id)
@Html.RequiredIndicatorLabelFor(m => m.DepreciationYear, new { @class = "col-sm-3 control-label no-padding-right" })
<div class="col-sm-7">
@Html.TextBoxFor(m => m.DepreciationYear, "", new { @class = "form-control popupwindowinput" })
</div>
</div>
<div class="form-group">
@Html.RequiredIndicatorLabelFor(m => m.SalvageValue, new { @class = "col-sm-3 control-label no-padding-right" })
<div class="col-sm-7">
@Html.TextBoxFor(m => m.SalvageValue, "", new { @class = "form-control popupwindowinput" })
</div>
</div>
<div class="form-group">
@Html.RequiredIndicatorLabelFor(m => m.Comment, new { @class = "col-sm-3 control-label no-padding-right" })
<div class="col-sm-7">
@Html.TextAreaFor(m => m.Comment, new { @class = "form-control", rows = 3 })
</div>
</div>
<div class="form-group">
<div class="text-center">
<button class="btn btn-info" type="submit">
@Resources.CommonButtonSubmit
</button>
@*<button class="btn btn-info margin-left-5 closeWindowBtn" type="button">
@Resources.CommonButtonCancle
</button>*@
</div>
</div>
</form>

5、PartialView验证的坑

参照

https://stackoverflow.com/questions/9490322/mvc-3-razor-partial-view-validation-is-not-working

在partialView加载渲染后需要重新解析form的客户端验证。并且需要在提交按钮时验证下form

<script>
$(function () {
jQuery.validator.unobtrusive.parse();
$('#importForm').removeData('validator');
$('#importForm').removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse('#importForm');
$("#submitBtn").click(function() {
if (!$("#importForm").valid()){
return false;
}
       $("#importForm").submit();
return true;
});
});
</script>

mvc partialView+kendo window的更多相关文章

  1. mvc partialView断点调试问题

    mvc中的partialview 在前端f12调试时,默认看不到代码的.  在Js中加上debugger;  调试时会走到断点,多出个VM打头的局部视图页面.

  2. MVC PartialView

      参考 Updating an MVC Partial View with Ajax RenderPartial vs RenderAction vs Partial vs Action in MV ...

  3. ASP.NET MVC PartialView用法

    子页面AreaSelect.cshtml页面的Controller代码: public ActionResult AreaSelect() { return PartialView(); } 父页面前 ...

  4. MVC PartialView 方式实现点击加载更多

    <table id="MovieListing"> </table><div> <button id="btnShowMore& ...

  5. MVC PartialView使用

    https://blog.csdn.net/mss359681091/article/details/51181037

  6. Kendo UI for ASP.NET MVC 的一些使用经验(转)

    转自 http://blog.csdn.net/dj2008/article/details/45313805 最近的项目里用到了Kendo UI.这货很好很强大,但可惜官方文档组织的并不是很好,有很 ...

  7. [转]Upgrading to Async with Entity Framework, MVC, OData AsyncEntitySetController, Kendo UI, Glimpse & Generic Unit of Work Repository Framework v2.0

    本文转自:http://www.tuicool.com/articles/BBVr6z Thanks to everyone for allowing us to give back to the . ...

  8. Asp.net mvc Kendo UI Grid的使用(三)

    上一篇的操作已经能够显示基本数据了,这次介绍一下如何进行数据操作以及显现自定义命令. 第一步当然还是准备数据: [HttpPost] public ActionResult PersonalList_ ...

  9. Asp.net mvc Kendo UI Grid的使用(二)

    上一篇文章对Kendo UI做了一些简单的介绍以及基本环境,这篇文章来介绍一下Grid的使用 先上效果图: 要实现这个效果在Controller在要先导入Kendo.Mvc.UI,Kendo.Mvc. ...

随机推荐

  1. 理解WidowManager

    --摘自<Android进阶解密> *WindowManger的关联类* 1.Window是一个抽象类,具体的实现类为PhoneWindow,它对View进行管理.WindowManage ...

  2. 微信tinker 热修复

    Tinker 是微信官方的Android热补丁解决方案,它支持动态下发代码.So库以及资源,让应用能够在不需要重新安装的情况下实现更新.当然,你也可以使用Tinker来更新你的插件. github:h ...

  3. jQuery 对象 等操作

    /////////////////////下面为文件夹重命名功能区///////////////////////// $(".wpul .rename").click(functi ...

  4. laravel之ORM增删改查数据

    1.首先在控制器中添加方法,然后添加路由,接着在模型中操作: 以下是模型 2.以下是控制器中的操作 一下是通过ORM进行更新 删除数据

  5. linux中vi编辑

    crt退出全屏:点击Alt+enter键 linux上传下载文件     Xftp.Filezilla.Winscp等工具 命令      sz  test.txt    #下载test.txt文件 ...

  6. 周末没事干就看CSS JS Python ThinkPHP的书,照着例子运行就行,可以增强信心(www.delphihtmlcomponents.com 是神器,也可以帮助我学习。还有虚拟机运行Web)

    https://www.javatpoint.com/javascript-tutorialhttps://www.javatpoint.com/html-tutorialhttps://www.ja ...

  7. 解决配置Windows Update失败问题

    大家都清楚电脑总是需要更新一些补丁,不过,很多系统用户发现更新了补丁之后,开机会出现windows update更新失败的情况,提示“配置Windows Update失败,还原更改,请勿关闭计算机”信 ...

  8. 第 1 章 JS变量、作用域

    目录 一. 判断变量类型 二.作用域 和 上下文 1. 作用链 2. 上下文(this) 二.JS的解析机制 1. 预解析 三.垃圾收集 内存管理销毁 @(es5) 基本类型 引用类型 一. 判断变量 ...

  9. FPGA小例子

    AND ---与门:OR --- 或门:INV --- 非门:NAND --- 与非门:NOR --- 或非门:XOR --- 异或门:XNOR ---同或门:MUX --- 数据选择器: 1.使用一 ...

  10. 两个ArrayList之间求交并补

    class ArraylistCalculate{ // 两个整数集求差集 public ArrayList<Integer> integerArrayListDifference( Ar ...