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. ...
随机推荐
- 使用Python下载文件
python -c "with open('/tmp/file.sh', 'wb') as f: import urllib2; f.write(urllib2.urlopen('http: ...
- vscode断点调试简单的服务端文件
一.无配置文件时,如何调试? 1.安装code命令打开vscode,快捷键command + shift + p,输入shell command,选择install 'code' command in ...
- open
open服务指的是封装的订单流接口,给外部第三方提供使用.(当然也可以区别的名字,我司这么叫而已,并且是用Java写的,谁晓得为什么不选择PHP来写)通过open api合作方就可以通过调用接口直接下 ...
- Sublime编译器快捷键大全
Ctrl+Shift+P:打开命令面板 Ctrl+P:搜索项目中的文件 Ctrl+G:跳转到第几行 Ctrl+W:关闭当前打开文件 Ctrl+Shift+W:关闭所有打开文件 Ctrl+Shift+V ...
- ruby配合gem使用sass
Ruby环境安装 1.Ruby安装包下载地址:http://rubyinstaller.org/downloads/下载对应系统版本的安装包: 2.双击rubyinstaller-2.2.3-x64. ...
- linux打包文件和压缩
1.解压:tar -zxvf archive.tar , unzip file1.zip 2.压缩:tar -cvfz archive.tar.gz dir1 , zip file1.zip file ...
- 13树莓派手动安装Home Assistant
2017-09-05 00:53:02 https://home-assistant.io/docs/installation/raspberry-pi/ 已经安装步骤安装了带桌面的树莓派系统,在SD ...
- 2017 CCPC Qinhuangdao Site
A. Balloon Robot 假设机器人$0$时刻位于$0$号位置,那么每个气球所需的时间为$(s_a-b)\bmod m$. 将所有气球按这个时间排序,枚举每个气球的时间作为偏移量,得出最优解即 ...
- js 对时间进行判断 现在的时间是否在后台给的开始时间 和 结束时间 内 (时间格式为:2018-09-03 09:20:30)
function status(item){ let now = Date.parse(new Date()); let startString = Date.parse(new Date(Date. ...
- Elastic 之倒排索引(二)
常规索引建立: 文档-->关键词的映射过程(正向索引) 缺点:费时 便利全部文档 倒排反向建立索引: 关键词-->文档的映射 反向到倒排索引:将索引的关键词出现的文档的位置和出现频率通过文 ...