• 用于json的 .ashx 小细节



    public void ProcessRequest(HttpContext context)
    {

              switch (action)

                {
                    case "attribute_field_validate": //验证扩展字段是否重复
                        attribute_field_validate(context);
                        break;
                    case "channel_category_validate": //验证频道分类目录是否重复
                        channel_category_validate(context);
                        break;case "get_builder_html": //生成静态页面
                        get_builder_html(context);
                        break;
                }
    }

    上面个用switch 来判断,一个语句就解决一个问题

    下面是  Switch判断后 用来执行对应 函数

        #region 验证扩展字段是否重复============================
            private void attribute_field_validate(HttpContext context)
            {
                string column_name = MXRequest.GetString("param");
                if (string.IsNullOrEmpty(column_name))
                {
                    context.Response.Write("{ "info":"名称不可为空", "status":"n" }");
                    return;
                }
                BLL.article_attribute_field bll = new BLL.article_attribute_field();
                if (bll.Exists(column_name))
                {
                    context.Response.Write("{ "info":"该名称已被占用,请更换!", "status":"n" }");
                    return;
                }
                context.Response.Write("{ "info":"该名称可使用", "status":"y" }");
                return;
            }
            #endregion

    这样优化一下,不但界面美观,容易理解->而且一个case一个功能

        
  • 相关阅读:
    Python 字符串和list的功能翻译
    python .strip()
    python 查看对象功能
    python 字典
    洛谷 P1144 最短路计数 Label:水
    心疼自己,再见
    初赛复习 //附复习资料
    51Nod 1079 中国剩余定理 Label:数论
    转载 乘法逆元
    51Nod 1136 欧拉函数 Label:数论
  • 原文地址:https://www.cnblogs.com/0to9/p/4988107.html
Copyright © 2020-2023  润新知