ASP.NET Zero--12.一个例子(5)商品分类管理-编辑分类
1.添加编辑按钮
actions: {
title: app.localize('Actions'),//操作列
width: '15%',
sorting: false,
display: function (data) {
var $span = $('<span></span>');
$('<button class="btn btn-default btn-xs" title="' + app.localize('Edit') + '"><i class="fa fa-edit"></i></button>')
.appendTo($span)
.click(function () {
_editModal.open({ id: data.record.id });
});
return $span;
}
},

2.模态框创建
@using MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Models.Common.Modals
@Html.Partial("~/Areas/Mpa/Views/Common/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel("编辑分类")) <div class="modal-body">
<form name="CategoryForm">
<input type="hidden" name="Id" value="@Model.Id" />
<div class="form-group form-md-line-input form-md-floating-label">
<input type="text" name="Name" value="@Model.Name" class="form-control edited" required >
<label>名称</label>
</div>
</form>
</div> @Html.Partial("~/Areas/Mpa/Views/Common/Modals/_ModalFooterWithSaveAndCancel.cshtml")
var EditCategoryModal = (function ($) {
app.modals.EditCategoryModal = function () { var _modalManager;
var _categoryService = abp.services.app.category;
var _$categoryForm = null; this.init = function (modalManager) {
_modalManager = modalManager; _$categoryForm = _modalManager.getModal().find('form[name=CategoryForm]');
_$categoryForm.validate();
}; this.save = function () {
if (!_$categoryForm.valid()) {
return;
} var category = _$categoryForm.serializeFormToObject(); _modalManager.setBusy(true);
_categoryService.updateCategory(
category
).done(function () {
abp.notify.info(app.localize('SavedSuccessfully'));
_modalManager.close();
abp.event.trigger('app.editCategoryModalSaved');
}).always(function () {
_modalManager.setBusy(false);
});
};
};
})(jQuery);
3.添加方法
void UpdateCategory(CreateCategoryInput input);
CategoryOutput GetCategoryForEdit(EntityRequestInput input);
public void UpdateCategory(CreateCategoryInput input)
{
int count = _categoryRepository.Count(a => a.Name.Equals(input.Name) && a.Id!=input.Id);
if (count > )
{
throw new UserFriendlyException("分类名称已存在!");
}
var category=_categoryRepository.Get(input.Id);
category.Name = input.Name;
} public CategoryOutput GetCategoryForEdit(EntityRequestInput input)
{
var category = _categoryRepository.Get(input.Id);
return new CategoryOutput()
{
Id = category.Id,
Name = category.Name
};
}
4.修改Index.js
...
var _createModal = new app.ModalManager({
viewUrl: abp.appPath + 'Mpa/Category/CreateModal',//加载视图
scriptUrl: abp.appPath + 'Areas/Mpa/Views/Category/_CreateModal.js',//加载对应js
modalClass: 'CreateCategoryModal'
}); var _editModal = new app.ModalManager({
viewUrl: abp.appPath + 'Mpa/Category/EditModal',
scriptUrl: abp.appPath + 'Areas/Mpa/Views/Category/_EditModal.js',
modalClass: 'EditCategoryModal'
});
...
//事件注册
abp.event.on('app.createCategoryModalSaved', function () {
getCategories(true);
}); abp.event.on('app.editCategoryModalSaved', function () {
getCategories(true);
});
5.控制器
private ICategoryAppService _categoryAppService;
public CategoryController(ICategoryAppService categoryAppService)
{
_categoryAppService = categoryAppService;
}
...
public ActionResult EditModal(int id)
{
CategoryOutput category=_categoryAppService.GetCategoryForEdit(new EntityRequestInput(id));
CategoryViewModel categoryViewModel=new CategoryViewModel()
{
Id = category.Id,
Name = category.Name
};
return PartialView("_EditModal", categoryViewModel);
}
6.添加ViewModel

public class CategoryViewModel
{
public int Id { get; set; }
public string Name { get; set; }
}
7.测试

ASP.NET Zero--12.一个例子(5)商品分类管理-编辑分类的更多相关文章
- [asp.net core]SignalR一个例子
摘要 在一个后台管理的页面想实时监控一些操作的数据,想到用signalR. 一个例子 asp.net core+signalR 使用Nuget安装包:Microsoft.AspNetCore.Sign ...
- ASP.NET Zero--13.一个例子(6)商品分类管理-删除分类
1.添加按钮 首先添加一个删除按钮,打开文件Index.js[..\MyCompanyName.AbpZeroTemplate.Web\Areas\Mpa\Views\Category\Index.j ...
- ASP.NET Zero--15.一个例子(8)商品分类管理-权限控制
1.添加权限常量 打开文件AppPermissions.cs [..\MyCompanyName.AbpZeroTemplate.Core\Authorization\AppPermissions.c ...
- ASP.NET Zero--8.一个例子(1)菜单添加
以一个商品分类管理功能来编写,代码尽量简单易懂.从一个实体开始,一直到权限控制,由浅到深一步步对功能进行完善. 1.打开语言文件 [..\MyCompanyName.AbpZeroTemplate.C ...
- 这算是ASP.NET MVC的一个大BUG吗?
这是昨天一个同事遇到的问题,我觉得这是一个蛮大的问题,而且不像是ASP.NET MVC的设计者有意为之,换言之,这可能是ASP.NET MVC的一个Bug(不过也有可能是保持原始请求数据而作的妥协). ...
- 返璞归真 asp.net mvc (12) - asp.net mvc 4.0 新特性之移动特性
原文:返璞归真 asp.net mvc (12) - asp.net mvc 4.0 新特性之移动特性 [索引页][源码下载] 返璞归真 asp.net mvc (12) - asp.net mvc ...
- 通过一个例子了解Ajax
Ajax指的Asyncronous JavaScript and XML Ajax并不是什么新的编程语言, 它是现有一些东西的应用.从它的名称中就可以看出来 假如我们设想, 浏览器展示了一个页面,但需 ...
- [ASP.NET MVC2 系列] ASP.Net MVC教程之《在15分钟内用ASP.Net MVC创建一个电影数据库应用程序》
[ASP.NET MVC2 系列] [ASP.NET MVC2 系列] ASP.Net MVC教程之<在15分钟内用ASP.Net MVC创建一个电影数据库应用程序> ...
- 《The art of software testing》的一个例子
这几天一直在看一本书,<The art of software testing>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...
随机推荐
- Git 常用命令速查表(三)
http://blog.csdn.net/sunboy_2050/article/details/7529841
- BLDC(无刷直流电机)应用相关
1.基于XC866的直流无刷电机简易正弦波控制 http://blog.gkong.com/hushunlin_219521.ashx 2.无刷直流电机的PWM调制方式介绍 http://blog.g ...
- C#使用FFmpeg 将视频格式转换成MP4示例
一.常用视频格式分辨率 640x480p 720p格式,分辨率为1280×720p / 60Hz,行频为45kHz 1080p格式,分辨率为1920×1080逐行扫描,专业格式 二.FFmpeg部分参 ...
- Codeforces#371 Div2
这是一场非常需要总结的比赛,交了3题,最后终测的时候3题全部没过,一下掉到了绿名,2333 Problem A 题意:给定区间[l1,r1],[l2,r2],然后给定一个整数k,求区间当中相交的元素, ...
- JS操作DOM对象——JS基础知识(四)
一.JavaScript的三个重要组成部分 (1)ECMAScript(欧洲计算机制造商协会) 制定JS的规范 (2)DOM(文档对象模型)重点学习对象 处理网页内容的方法和接口 (3)BOM(浏览器 ...
- PHP 领域逻辑与数据库映射
http://blog.csdn.net/hguisu/article/details/7569968
- The Willpower Instinct
https://book.douban.com/subject/7043452/ 1.冥想2.健康饮食(低GI.素食为主,未加工食物为主).低GI食物使血糖稳定(蛋白.麦片.粗纤谷类.豆类.水果蔬菜) ...
- mysqldump导入导出mysql数据库
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- AppServ设置虚拟主机 及域名连接
1: 安装好AppServ2.5.9软件,官网是:http://www.appservnetwork.com/ ,2.59下载地址是:http://nchc.dl.sourceforge.net/so ...
- ZOJ 3931 Exact Compression
题目看了半小时才看懂的. 题意:首先根据给出的序列,构造出哈夫曼树,构造出来的是一棵二叉树,每个节点都有一个权值,每个节点的两个儿子只能取一个,问能否使取出来的节点权值之和刚好等于e. 这样一分析就很 ...