mvc partialView+kendo window
在写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的更多相关文章
- mvc partialView断点调试问题
mvc中的partialview 在前端f12调试时,默认看不到代码的. 在Js中加上debugger; 调试时会走到断点,多出个VM打头的局部视图页面.
- MVC PartialView
参考 Updating an MVC Partial View with Ajax RenderPartial vs RenderAction vs Partial vs Action in MV ...
- ASP.NET MVC PartialView用法
子页面AreaSelect.cshtml页面的Controller代码: public ActionResult AreaSelect() { return PartialView(); } 父页面前 ...
- MVC PartialView 方式实现点击加载更多
<table id="MovieListing"> </table><div> <button id="btnShowMore& ...
- MVC PartialView使用
https://blog.csdn.net/mss359681091/article/details/51181037
- Kendo UI for ASP.NET MVC 的一些使用经验(转)
转自 http://blog.csdn.net/dj2008/article/details/45313805 最近的项目里用到了Kendo UI.这货很好很强大,但可惜官方文档组织的并不是很好,有很 ...
- [转]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 . ...
- Asp.net mvc Kendo UI Grid的使用(三)
上一篇的操作已经能够显示基本数据了,这次介绍一下如何进行数据操作以及显现自定义命令. 第一步当然还是准备数据: [HttpPost] public ActionResult PersonalList_ ...
- Asp.net mvc Kendo UI Grid的使用(二)
上一篇文章对Kendo UI做了一些简单的介绍以及基本环境,这篇文章来介绍一下Grid的使用 先上效果图: 要实现这个效果在Controller在要先导入Kendo.Mvc.UI,Kendo.Mvc. ...
随机推荐
- webpack打包后的文件
用了webpack打包工具,你是不是有时会疑惑,写了一个很简单的函数,结果生成那么多东西,而且还没有问题?下面,我从三种情况来分析打包后的入口文件,帮助自己理解webpack打包,也为平时定位产出目录 ...
- PostgreSQL自学笔记:3 数据库的基本操作
3 数据库的基本操作 3.1 创建数据库 3.1.1 使用对象浏览器创建数据库 [Server] -> PostgreSQL 9.6 -> 数据库,右击 -> 创建 通常: 数据库: ...
- 字符串函数之Strtok()函数
Strtok()函数详解: 该函数包含在"string.h"头文件中 函数原型: char* strtok (char* str,constchar* delimiters ) ...
- flask之一些凌乱知识点
本篇导航: session组件 上下文与内置函数 pymysql问题 模版问题 一.session组件 1.session组件简介 flask-session是flask框架的session组件,由于 ...
- (89)Wangdao.com第二十二天_JavaScript DocumentFragment 节点
DocumentFragment 节点 代表一个文档的片段,本身就是一个完整的 DOM 树形结构. 它没有父节点,.parentNode 返回 null 可以插入任意数量的子节点. 不属于当前文档,操 ...
- [Codeforces Round #508 (Div. 2)][Codeforces 1038E. Maximum Matching]
前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v ...
- 简单的SQL查询,循环插入
- Server response error code:404, error:{"ret":-1, "msg":"invalid appkey"}
Server response error code:404, error:{"ret":-1, "msg":"invalid appkey" ...
- graph engine
有个侥幸的机会,参与了微软的项目,侥幸的接触了,graph engine图形数据库,感觉很是新颖,做点记录,和大家分享,理解有限,发现不足之处,还请指点. 微软发分布式图处理引擎GraphEngine ...
- NetBeans GUI tests on Jenkins + Windows (转)
from http://forgetfulprogrammer.wordpress.com/tag/interact-with-desktop/ Running NetBeans applicatio ...