1.打开Index视图

页面中添加一个按钮,代码如下:
<div class="row margin-bottom-5">
<div class="col-xs-6">
<div class="page-head">
<div class="page-title">
<h1>
<span>分类</span> <small>@L("CategoryManager")</small>
</h1>
</div>
</div>
</div>
@*这里是添加的按钮代码*@
<div class="col-xs-6 text-right">
<button id="CreateNewCategoryButton" class="btn btn-primary blue"><i class="fa fa-plus"></i>添加分类</button>
</div>
</div>
效果如下:
 
点击按钮会弹出一个模态框进行分类添加
 

2.模态框创建

在Category目录下新建一个视图_CreateModal.cshtml,代码如下:
@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">
<div class="form-group form-md-line-input form-md-floating-label">
<input class="form-control" type="text" name="Name">
<label>名称</label>
</div>
</form>
</div>
@Html.Partial("~/Areas/Mpa/Views/Common/Modals/_ModalFooterWithSaveAndCancel.cshtml")
同样再新建一个js文件_CreateModal.js,代码如下:
(function ($) {

    app.modals.CreateCategoryModal = function () {
var _categoryService = abp.services.app.category;
var _$categoryForm = null; var _modalManager;
this.init = function (modalManager) {
_modalManager = modalManager;
//取出Form表单
_$categoryForm = _modalManager.getModal().find('form[name=CategoryForm]');
}; this.save = function () {
//序列化参数
var category = _$categoryForm.serializeFormToObject();
_modalManager.setBusy(true);
_categoryService.createCategory(
category
).done(function () {
abp.notify.info(app.localize('SavedSuccessfully'));
_modalManager.close();
abp.event.trigger('app.createCategoryModalSaved');
}).always(function () {
_modalManager.setBusy(false);
});
};
};
})(jQuery);

3.添加新建方法

打开ICategoryAppService文件,添加如下代码:
void CreateCategory(CreateCategoryInput input);
对应的实现类CategoryAppService,添加如下代码:
public void CreateCategory(CreateCategoryInput input)
{
_categoryRepository.Insert(new Category()
{
Name = input.Name
});
}

4.添加Dto

在Dto目录下新建一个类CreateCategoryInput.cs,代码如下:
public class CreateCategoryInput:EntityDto,IInputDto
{
public string Name { get; set; }
}

5.修改Index.js

最后打开Index.js,添加代码如下:
...
var _categoryService = abp.services.app.category; var _createModal = new app.ModalManager({
viewUrl: abp.appPath + 'Mpa/Category/CreateModal',//加载视图
scriptUrl: abp.appPath + 'Areas/Mpa/Views/Category/_CreateModal.js',//加载对应js
modalClass: 'CreateCategoryModal'
});
...
//页面加载完执行
getCategories(); //添加点击事件
$('#CreateNewCategoryButton').click(function () {
_createModal.open();
}); //事件注册
abp.event.on('app.createCategoryModalSaved', function () {
getCategories(true);
});

6.控制器

打开CategoryController,添加如下代码:
public ActionResult CreateModal()
{
return PartialView("_CreateModal");
}
最后,重新生成项目,刷新页面,点击添加分类

最新文章

  1. Azure Application Gateway (3) 设置URL路由
  2. Docker - Docker基础命令及使用
  3. [Effective JavaScript 笔记]第42条:避免使用轻率的猴子补丁
  4. MapReduce: 一个巨大的倒退
  5. 对list集合中的对象进行排序(转载)
  6. careercup-递归和动态规划 9.7
  7. Gengxin讲STL系列——Set
  8. cookie笔记(一)
  9. 5.VBS的一些约定,提高可读性
  10. SpringMVC底层数据传输校验的方案
  11. AngularJS1.X学习笔记11-服务
  12. js 浏览器兼容css中webkit、Moz、O、ms...写法封装(es6语法)
  13. 68.jq---tab选项实现网页定点切换
  14. SQL 连接(内连接,外连接)
  15. PHP运算符知识
  16. git常用命令速查:创建,修改提交,撤销,切换分支,合并分支,变基解决冲突
  17. centos安装bundle文件
  18. Vue(一)创建第一个Vue程序
  19. zabbix中配置当memory剩余不足20%时触发报警
  20. Error:java: 无效的源发行版: 1.8

热门文章

  1. Erlang常用代码段
  2. MySQL replace into 说明(insert into 增强版)
  3. ExtJs--12--Ext定义类的requires uses singleton 三个配置项的使用
  4. Visual Studio 单元测试之四---Generic测试
  5. __declspec(novtable)keyword
  6. 阻止check事件冒泡
  7. MyEclipse的真正价值——时间等于金钱
  8. 在ubuntu下把php的网页调试功能打开
  9. 基于Jcrop的图片上传裁剪加预览
  10. 使用rem设计移动端自适应页面一(转载)