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. ...
随机推荐
- Prime Distance POJ - 2689 (数学 素数)
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...
- [CQOI2015]网络吞吐量
Description: 给你一个图,每个点可以被经过\(a_i\)次,求有多少个人可以走最短路到n点 Hint: \(n \le 500\) Solution: 极其水的一道题,就当做复习最短路板子 ...
- 【最短路+最大流】上学路线@安徽OI2006
目录 [最短路+最大流]上学路线@安徽OI2006 PROBLEM SOLUTION CODE [最短路+最大流]上学路线@安徽OI2006 PROBLEM 洛谷P4300 SOLUTION 先在原图 ...
- [Educational Round 5][Codeforces 616F. Expensive Strings]
这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...
- 壁虎书1 The Machine Learning Landscape
属性与特征: attribute: e.g., 'Mileage' feature: an attribute plus its value, e.g., 'Mileage = 15000' Note ...
- Lucene.net 的性能探究--Lucene.net 的并发处理能力到底有多强?
这篇博客并不是证明Lucene.net的性能有多强悍,实际上Lucene.net的并发能力并不让人很满意,这得看你怎么用它. 因为Lucene 本身就是一个搜索引擎的基础框架,相当于一辆车子的发动机, ...
- awk 复习
awk 的再次学习!!!! awk 的一般模式 awk '{parttern + action }' {filename} , 提取/etc/passwd 的用户 awk -F ":&quo ...
- 使用maxwell实时同步mysql数据到kafka
一.软件环境: 操作系统:CentOS release 6.5 (Final) java版本: jdk1.8 zookeeper版本: zookeeper-3.4.11 kafka 版本: kafka ...
- javascript 表达式
// for(表达式1;表达式2;表达式3){// 循环体语句;// }// 先执行表达式1,在执行2表达式,// 如果2表达式结果为false,退出循环 ...
- Windows10 磁盘100%解决办法
此电脑->管理->任务计划程序->\Microsoft\Windows 一.\MemoryDiagnostic 禁用:ProcessMemoryDiagnosticEvents和Ru ...