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>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...
随机推荐
- Entity Framework Power Tools Beta 3
http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/ PM> Install-P ...
- Android JNI入门第六篇——C调用Java
本篇将介绍在JNI编程中C调用Java实现. 源码下载地址:http://download.csdn.net/detail/xyz_lmn/4868265 关键代码: java: public cla ...
- JQuery使用和选择器
1.优点 (1)能解决浏览器的兼容性JS问题 (2)解决JS代码冗余的问题 (3)动画效果更容易实现 2.压缩过的和不压缩的区别 (1)开发过程中用未压缩的:上线后用压缩版本. (2)版本问题:1.X ...
- 配置 nginx location 实时查看 php-fpm 的状态
在Nginx.conf 里配置 location ~ ^/status$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_ ...
- C# DateTime变量不能赋null值
使用定时器的时候: DateTime aimtime=DateTime.Now.AddSeconds(1); CheckTimer() { if(DateTime.Now.CompareTo(aimt ...
- Android点击Button按钮的四种事件监听方法总结
首先我们在activity_main.xml里面先定义一个Button空间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <RelativeLayout xmlns:a ...
- MIPI-3
上一篇文章讲了以下D_PHY层,这只是最底层的,针对于显示,上层由分出了四种,由专门的工作组进行定义,显示器方面叫做display wrok group,主要分为 DSC(display comman ...
- X-006 FriendlyARM tiny4412 u-boot移植之Debug串口用起来
<<<<<<<<<<<<<<<<<<<<<<<<< ...
- osgEarth基础入门(转载)
osgEarth基础入门 osgEarth是基于三维引擎osg开发的三维数字地球引擎库,在osg基础上实现了瓦片调度插件,可选的四叉树调度插件,更多的地理数据加载插件(包括GDAL,ogr,WMS,T ...
- Ehcache jgroups方式同步缓存出现问题总结
ehcache配置文件按官网配置如下: <?xml version="1.0" encoding="UTF-8"?> <ehcache> ...