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. ...
随机推荐
- vim编辑器操作命令
vim [参数] [文件 ..] 编辑指定的文件 或: vim [参数] - 从标准输入(stdin)读取文本 或: vim [参数] -t ...
- CodeForces - 1025C 字符串处理,画一个圆。。。
题目链接: https://vjudge.net/problem/1810469/origin 题目大意: 给你一个字符串,中间切一刀,左右两边均反转,然后右边的串拼接到左边上. 思路: 比如 aa ...
- TCP/IP协议、HTTP协议、SOCKET通讯详解
1.TCP连接TCP(Transmission Control Protocol) 传输控制协议.TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握确认建立一个连接.位码即tcp标志位 ...
- dnsmasq配置
介绍 dnsmasq是一个dns和dhcp服务 参数说明 dhcp-sequential-ip 默认情况下Dnsmasq分配ip是根据目标机的mac地址按一定的hash规则来的.这样每个目标机在租约期 ...
- java实现单链表反转(倒置)
据说单链表反转问题面试中经常问,而链表这个东西相对于数组的确稍微难想象,因此今天纪录一下单链表反转的代码. 1,先定义一个节点类. 1 public class Node { 2 int index; ...
- clipboard.js一个可以在移动端一键复制的插件
网址:https://clipboardjs.com/ 使用方法: 1.引入js <script src="dist/clipboard.min.js"></sc ...
- MAC下 mySQL及workbench安装
1.首先去mysql 网站下载安装包,https://dev.mysql.com/downloads/mysql/ 选择第一个.dmg格式的下载安装 2.安装完成后,在System Preferenc ...
- angular.equals()
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 01_ if 练习
prompt() 弹出一个对话框,该对话框中会带有一个文本框,用户可以在文本框中输入一段内容. 该函数需要一个字符串作为参数,用作对话框的提示文字. 用户输入内容,将会作为函数返回值.可 ...
- react_结合 redux - 高阶函数 - 高阶组件 - 前端、后台项目打包运行
Redux 独立的集中式状态管理 js 库 - 参见 My Git 不是 react 库,可以与 angular.vue 配合使用,通常和 react 用 yarn add redux import ...