Based on the rapid development of the framework EasyUi

Look at the chart, below this simple add, delete, change, check, if they write code to achieve these two pages how many lines of code needed?

If we have similar add, delete, change, search, how many lines of code they need?

I recently engaged in the rapid development framework, no more than 100 lines of code.

Two codes are as follows:

1, list page:

@{    
    ViewBag.Title = "**** - 部门管理";
    ViewBag.MenuType = "Manage";
    ViewBag.MenuName = "部门管理";
}
@section HeadContent{
}
<div class="tit">
    <span style="float: left;"><a href="@Url.Content("~/")" target="_self">首页</a>部门管理</span>
    <span style="float: right; padding-right: 10px;"></span>
</div>
<div class="main">
    <div class="main_con">
        <table id="tbDataList" class="easyui-datagrid">
        </table>
    </div>
</div>
<div class="clear">
</div>
@section FootContent{
    <script type="text/javascript">[=columnsSettingwere() {
            Function
        $ (
                    {Field: ' the Name ' , title: ' department name ' , width: 100 , the sortable: to true }, 
                    {Field: ' SortNum ' , title: ' sort No. ' , width: 80 }, 
                    {Field: ' Remark, the ' , title : ' Remarks ' , width: 80 }, 
                    {Field: ' NoticeEmails ' , title: ' e-mail notification lists ' , width:200 },
                    { field: 'CreateManEnName', title: '添加人', width: 120 },
                    { field: 'CreateTime', title: '添加时间', width: 80, formatter: function (value) {
                        if (value != null) {
                            return value.CDate();
                        }
                    }
                    }
                ];

            initParam.url = '/DeptManage/GetDeptList';
            initParam.queryParams = {};
            initParam.width = 1077;
            //initParam.height= 600;
            initParam.columns = columnsSetting;
            initParam.toolbar = builderAddEditDelToolbar('部门管理', "/DeptManage", 500, 500);
            builderDatagrid(initParam);
        });    
    </script>
}

2, add / edit page code is as follows:

@model Cigna.ForbiddenLeads.Model.RoleModel
@{    
    ViewBag.Title = "**** - 角色管理";
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
}
@section HeadContent{
}
@using (Html.BeginForm("EditForm", "RoleManage", FormMethod.Post, new { id = "EditForm", name = "EditForm", onsubmit = "return Check()" }))
{
    <div class="ab" style="margin-top: 20px;">
        <span class="abname"><span class="red">*</ span> <span</Role Name:>Spanclass="abinput">
            @Html.TextBoxFor(model => model.Name, new { title = "角色名称", @class = "easyui-validatebox", required = "true" })
        </span>
    </div>
    <div class="ab">
        <span class="abname"><span class="red">*</span>权限:</span> <span class="abinput">
        @Html.CheckBox("AllowUpload", @Model.AllowUpload == "Y" ? true : false)上传
        @Html.CheckBox("AllowDown", @Model.AllowDown == "Y" ? true : false)下载    
        @Html.CheckBox("AllowManage", @Model.AllowManage == "Y" ? true : false)管理 </span>
    </div>
    <div class="ab">
        <span class="abname">备注:</span><span class="abinput">
            @Html.TextAreaFor(model => model.Remark, new { title = "备注",@rows = "6", @cols = "80", @style = "width: 250px;" })
        </span>
    </div>    
    <br />    
    @Html.Partial("Button")
    @Html.HiddenFor(model => model.ID)        
}

Why, to achieve so many features, only the code that sparse reception less than 100 lines?

That is because a lot of code reuse, are written in other libraries.

For example, the list page painting Datagrid, such as add, delete, change button events, which are common, written in Common.js, the transmission parameters can be achieved by the corresponding function.

For example, add / modify page submission and return trigger event of the button, it is written in a partial view in the pages of one line of code calls it.

So that all new / modified pages, are calling this one a partial view.

For example, back stage pass page parameters, ordinary practice, for controls on the page, one by one, gets its value, and then spread to the background, the practice here is to get all pages of the control value, assembled into Json, incoming the background, the background and then transferred to the corresponding entity, is not very handsome, very easy to do?

The key code is as follows:

Taiwan back pass parameters.

     <script type="text/javascript">
         $(function () {
             $("#btnSubmit").bind("click", function () {
                 var lastForm = $($("form").last());
                 if (!lastForm.form('validate')) return;
                 var formJSON = { dataJson: JSON2.stringify(lastForm.formtojson()) };

                 $.ajax({
                     url: lastForm.attr("action"),
                     type: 'post',
                     data: formJSON,
                     success: function (data) {
                         ajaxSuccessFun(data);
                     },
                     error: function (date, ddd) { }
                 })
             })
         });
    </script>

Background reception parameters:

            string json = RequestExtension.GetFormData();
            if (string.IsNullOrEmpty(json))
                return Json(new ResultMsg(500, "没有获取到参数"), JsonRequestBehavior.AllowGet);

            json = HttpUtility.UrlDecode(json);
            RoleModel viewModel = JsonExtension.JsDeserialize<RoleModel>(json);

Thus, the function basically, just to work, and are interested please leave a message, I went to, thank you.

 

Reproduced in: https: //www.cnblogs.com/ushou/p/3748426.html

Guess you like

Origin blog.csdn.net/weixin_34177064/article/details/93162606