首页 > 其他分享 >Edit.cshtml

Edit.cshtml

时间:2023-06-26 12:22:25浏览次数:58  
标签:function form Edit html cshtml var sel data

@{
    ViewData["Title"] = "Edit";
    Layout = "~/Views/Shared/_Layout_default.cshtml";
}

<form class="layui-form layui-form-pane" lay-filter="DataForm" style="margin:20px;">
    <div class="layui-form-item">
        <label class="layui-form-label">Floor:</label>
        <div class="layui-input-inline">
            <input type="hidden" name="Id" value="0" />
            <div id="divFloor" style="">
                <select name="Floor" id="sel_Floor" lay-filter="Floor" lay-search>
                    <option value="0"></option>
                </select>
            </div>
            <input type="text" id="txtFloor" autocomplete="off" style="display:none" disabled class="layui-input layui-disabled">
        </div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">IP:</label>
        <div class="layui-input-inline">
            <div id="divIP">
                <select name="IP" id="sel_IP" lay-filter="IP" lay-search>
                    <option value="0"></option>
                </select>
            </div>
            <input type="text" id="txtIP" autocomplete="off" style="display:none" disabled class="layui-input layui-disabled">
        </div>
        <div class="layui-input-inline">
            <div id="divIPMantissa">
                <select name="IPMantissa" id="sel_IPMantissa" lay-filter="IPMantissa" lay-search>
                    <option value="0"></option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">Mac Address:</label>
        <div class="layui-input-inline">
            <input type="text" name="MacAddress" lay-verify="required|Mac" placeholder="Mac Address" autocomplete="off" class="layui-input">
        </div>

        <label class="layui-form-label">Location:</label>
        <div class="layui-input-inline">
            @*<input type="text" name="Location" placeholder="Location" autocomplete="off" class="layui-input">*@
            <select name="Location" id="sel_Location" lay-filter="Location" lay-search>
                <option value="0"></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">Device/Computer:</label>
        <div class="layui-input-inline">
            @*<input type="text" name="Device" lay-verify="required" placeholder="Device/Computer" autocomplete="off" class="layui-input">*@
            <select name="Device" id="sel_Device" lay-filter="Device" lay-search>
                <option value="0"></option>
            </select>
        </div>

        <label class="layui-form-label">Node Name:</label>
        <div class="layui-input-inline">
            <input type="text" name="NodeName" placeholder="Node Name" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">User Name:</label>
        <div class="layui-input-inline">
            <input type="text" name="UserName" lay-verify="required" placeholder="User Name" autocomplete="off" class="layui-input">
        </div>

        <label class="layui-form-label">Expire At:</label>
        <div class="layui-input-inline">
            <input type="text" name="Expired" placeholder="Expire At" autocomplete="off" class="layui-input" id="Expired">
        </div>
    </div>

    <div class="layui-form-item">

        @*<label class="layui-form-label">Computer Name:</label>
            <div class="layui-input-inline">
                <input type="text" name="ComputerName" placeholder="Computer Name" autocomplete="off" class="layui-input">
            </div>*@

        <label class="layui-form-label">Purpose:</label>
        <div class="layui-input-inline">

            <select name="PurposeId" id="sel_Purpose" lay-filter="PurposeId" lay-search>
                <option value="0"></option>
            </select>
        </div>

    </div>

    <div class="layui-form-item" style="margin:30px 0px;">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="formDemo">Save</button>
            <button type="button" id="btnCancel" class="layui-btn layui-btn-primary">Cancel</button>
        </div>
    </div>
</form>

@section Scripts
{
    <script src="~/js/helper.js"></script>
    <script>

        layui.use('form', function () {
            var form = layui.form;
            var laydate = layui.laydate;


            var IPSegmentList = [];


            laydate.render({
                elem: '#Expired' //指定元素
            });


            var _Id = ObjParameter.getQueryStringDecodeURI("Id");


            //自定义验证规则
            form.verify({
                Mac: function (value, item) {
                    if (value.length != 12) {
                        return "Mac地址必须是12位字符"
                    }

                    //if (value.indexOf("o") > 0 || value.indexOf("O") > 0) {
                    //    return "Mac地址不能有字母O"
                    //}

                    var reg = new RegExp("^[0-9A-Fa-f]*$");
                    if (!reg.test(value)) {
                        return "Mac只能输入16进制数"
                    }

                }

            });


            //监听提交
            form.on('submit(formDemo)', function (data) {

                var formData = form.val('DataForm');
                formData.IP = formData.IP + "." + formData.IPMantissa;


                //console.log(_Id);

                if (_Id > 0) {
                    formData.IP = $("#txtIP").val().trim();
                    //formData.Floor = "";
                }
                console.log(formData);

                $.post("/IPList/UpdateableIgnoreColumnsWhere", formData, function (data) {

                    console.log(data);
                    if (data.code == 0) {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    } else {
                        layer.alert(data.msg, { title: '提示', icon: 5 });
                    }

                });

                return false;
            });


            $("#btnCancel").click(function () {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });

            //选择Floor下拉框事件
            form.on('select(Floor)', function (data) {

                console.log(data.value); //得到被选中的值
                var selVal = data.value;
                var result = IPSegmentList.filter(function (item) {
                    return item.Floor == selVal;
                });


                $("#sel_IP").empty();

                var html = '<option value="">Select IP Segment</option>';


                if (!objValidate.NotNull(selVal)) {
                    result = IPSegmentList;
                }
                $.each(result, function (i, v) {

                    html += '<option value="' + v.IPSegment + '">' + v.IPSegment + '</option>';

                });

                $("#sel_IP").append(html);
                layui.form.render("select");

            });

            form.on('select(IP)', function (data) {

                console.log(data.value); //得到被选中的值
                var selVal = data.value;

                //IP尾号选择
                $.ajax({
                    type: "Get",
                    url: "/IPList/QueryableNotDeletedAvailableIP",
                    async: true,
                    data: { IPSegment: selVal },
                    success: function (data) {
                        $("#sel_IPMantissa").empty();
                        var data = data.data;
                        var html = '<option value="">请选择</option>';
                        console.log(data);
                        var str = "";
                        $.each(data, function (i, v) {

                            str = v.IP.substring(v.IP.lastIndexOf(".") + 1);
                            html += '<option value="' + str + '">' + str + '</option>';

                        });

                        $("#sel_IPMantissa").append(html);
                        layui.form.render("select");

                    }
                });


                //IP楼层选择
                if (!objValidate.NotNull(selVal)) {
                    $("#sel_Floor").val("");
                    layui.form.render("select");
                    return false;
                }
                var result = IPSegmentList.find(function (item) {
                    return item.IPSegment == selVal;
                });

                $("#sel_Floor").val(result.Floor);
                layui.form.render("select");

            });

            var active = {
                //编辑时加载详情
                LoadDetails: function () {

                    $.ajax({
                        type: "Get",
                        url: "/IPList/QueryableInSingle",
                        async: true,
                        data: { Id: _Id },
                        success: function (data) {
                            var data = data.data;
                            form.val('DataForm', data);


                            $("#divFloor").css("display", "none");
                            $("#txtFloor").val(data.Floor).css("display", "block");



                            $("#divIP").css("display", "none");
                            $("#txtIP").val(data.IP).css("display", "block");

                            $("#divIPMantissa").css("display", "none");

                            $("#Expired").val(objDate.DateToStr(data.Expired, "/", 10, ''));

                            form.render();

                            //加载PurposeList数据
                            active.LoadPurposeList(data.PurposeId);
                        }
                    });
                }

                //加载PurposeList数据
                , LoadPurposeList: function (selectedVal) {

                    $.ajax({
                        type: "Get",
                        url: "/PurposeList/QueryableNotDeleted",
                        async: false,
                        data: {},
                        success: function (data) {
                            $("#sel_Purpose").empty();
                            var html = '<option value="">请选择</option>';
                            console.log(data.data);
                            $.each(data.data, function (i, v) {

                                if (selectedVal == v.PID) {
                                    html += '<option value="' + v.PID + '" selected>' + v.Name + '</option>';
                                } else {
                                    html += '<option value="' + v.PID + '">' + v.Name + '</option>';
                                }


                            });

                            $("#sel_Purpose").append(html);
                            layui.form.render("select");

                        }
                    });

                }


                //加载Floor数据
                , LoadFloorList: function () {

                    $.ajax({
                        type: "Get",
                        url: "/SegmentList/QueryableNotDeletedDistinct",
                        async: false,
                        data: {},
                        success: function (data) {

                            $("#sel_Floor").empty();
                            var data = data.data;
                            var html = '<option value="">请选择</option>';
                            console.log(data);
                            for (var i = 0; i < data.length; i++) {
                                html += '<option value="' + data[i] + '">' + data[i] + '</option>';
                            }

                            $("#sel_Floor").append(html);
                            layui.form.render("select");

                        }
                    });

                }

                //加载IPSegment数据
                , LoadIPSegmentList: function () {

                    $.ajax({
                        type: "Get",
                        url: "/SegmentList/QueryableNotDeletedWhere",
                        async: true,
                        data: {},
                        success: function (data) {

                            $("#sel_IP").empty();

                            var data = data.data;
                            IPSegmentList = data;
                            var html = '<option value="">Select IP Segment</option>';
                            /*console.log(data);*/
                            $.each(data, function (i, v) {
                                //console.log(v.Floor + " | " + selVal);
                                //if (v.Floor == selVal) {
                                html += '<option value="' + v.IPSegment + '">' + v.IPSegment + '</option>';
                                //}

                            });

                            $("#sel_IP").append(html);
                            layui.form.render("select");

                        }
                    });

                }

                //加载Device数据
                , LoadDeviceList: function () {

                    $.ajax({
                        type: "Get",
                        url: "/Enumeration/QueryableNotDeletedWhere",
                        async: false,
                        data: { Category: 'Device' },
                        success: function (data) {

                            $("#sel_Device").empty();
                            var data = data.data;
                            var html = '<option value="">请选择</option>';
                            console.log(data);
                            $.each(data, function (i, v) {

                                html += '<option value="' + v.Value + '">' + v.Text + '</option>';

                            });

                            $("#sel_Device").append(html);
                            layui.form.render("select");

                        }
                    });

                }
                //加载Location数据
                , LoadLocationList: function () {

                    $.ajax({
                        type: "Get",
                        url: "/Enumeration/QueryableNotDeletedWhere",
                        async: false,
                        data: { Category: 'Location' },
                        success: function (data) {

                            $("#sel_Location").empty();
                            var data = data.data;
                            var html = '<option value="">请选择</option>';
                            console.log(data);
                            $.each(data, function (i, v) {

                                html += '<option value="' + v.Value + '">' + v.Text + '</option>';

                            });

                            $("#sel_Location").append(html);
                            layui.form.render("select");

                        }
                    });

                }

            };

            //加载PurposeList数据
            active.LoadPurposeList();

            //加载Floor数据
            active.LoadFloorList();

            //加载IPSegment数据
            active.LoadIPSegmentList();

            //加载Device数据
            active.LoadDeviceList();

            //加载Location数据
            active.LoadLocationList();

            if (_Id > 0) {
                //加载详情
                active.LoadDetails();
            } else {

            }


        });
    </script>

}

 

标签:function,form,Edit,html,cshtml,var,sel,data
From: https://www.cnblogs.com/zyx321/p/17505328.html

相关文章

  • 强化学习从基础到进阶-常见问题和面试必知必答[5]::梯度策略、添加基线(baseline)、优势函
    强化学习从基础到进阶-常见问题和面试必知必答[5]::梯度策略、添加基线(baseline)、优势函数、动作分配合适的分数(credit)1.核心词汇策略(policy):在每一个演员中会有对应的策略,这个策略决定了演员的后续动作。具体来说,策略就是对于外界的输入,输出演员现在应该要执行的动作。一般地,我......
  • 强化学习从基础到进阶-常见问题和面试必知必答[5]::梯度策略、添加基线(baseline)、优势函
    强化学习从基础到进阶-常见问题和面试必知必答[5]::梯度策略、添加基线(baseline)、优势函数、动作分配合适的分数(credit)1.核心词汇策略(policy):在每一个演员中会有对应的策略,这个策略决定了演员的后续动作。具体来说,策略就是对于外界的输入,输出演员现在应该要执行的动作。一般地,我们......
  • 什么是 SAP Commerce Cloud SmartEdit 的 preview API
    PreviewAPI使得SmartEdit能够将商户网站加载到请求的体验环境上的iframe中。体验环境是指特定站点、目录和目录版本的商户网站,并且还可以是指定的语言、日期和时间。为了以指定的体验环境呈现商户网站,SmartEdit将请求的商户网站加载到请求的体验环境的iframe中。为了在请求的体验......
  • SAP Commerce Cloud 通过 SmartEdit 添加 Component 的一个例子
    如下图所示:位于ProductListLot内:url:http://localhost:4200/electronics-spa/en/USD/Open-Catalogue/Cameras/Digital-Cameras/Digital-Compacts/c/576观察到的OCC请求:https://localhost:9002/occ/v2/electronics-spa/cms/pages?pageType=CategoryPage&code=576&lang=en&......
  • BCDEdit是Windows操作系统中的命令行工具,用于管理启动配置数据(BCD)存储库。BCD存储库包
    BCDEdit是Windows操作系统中的命令行工具,用于管理启动配置数据(BCD)存储库。BCD存储库包含了系统引导时所需的引导设置、操作系统选项和相关配置信息。以下是一些关于BCDEdit的常见用途和功能:添加和删除条目:BCDEdit可以用于添加和删除引导条目,即不同的操作系统或启动选项。通过BCD......
  • Android,两个互相影响的EditText如何避免死循环
    简单来说,是一个类似如下的需求:两个EditText,假设名字分别是et1和et2;et1的值*一个数字,假设是4500=et2的值;当et1的值发生变化时,et2的值也发生变化,et2的值发生变化时,et1的值也发生变化,用过用简单的 TextWatcher就会发生死循环,如何避免,下面是这个例子代码的最核心部分,简单来说就......
  • Spartacus Storefront 里如何在 SmartEdit 访问环境下暂时禁用 Early login
    关于SpartacusEarlylogin的功能,即如果当前客户没有登录,则显示loginpage.而不是显示原始页面。有的客户期望Spartacus在SmartEdit环境下预览时,暂时禁掉这个功能。首先,开发人员应该分析与需求相关的所有后果并对安全威胁进行建模,然后考虑是否接受它们,例如:某些功能页......
  • SystemVerilog for Design Edition 2 Chapter 10
    SystemVerilogforDesignEdition2Chapter10SystemVerilogextendstheVeriloglanguagewithapowerfulinterfaceconstruct.Interfacesofferanewparadigmformodelingabstraction.Theuseofinterfacescansimplifythetaskofmodelingandverifying......
  • 如何实现带有颜色文本的日志框_使用HTMLEditor模拟
    如何实现带有颜色文本的日志框_使用HTMLEditor模拟HTMLEditor是一个强大的html编辑器,可以方便的编辑各种html元素并得到html文本。比之TextArea要强大很多,因为TextArea中所有的文本只能有一种样式。如果想要实现一个日志框,其中普通信息、警告信息、错误信息使用不同......
  • editView 中字里行间加入动画
    setContentView(R.layout.main);TextViewtextView=(TextView)findViewById(R.id.textview);SpannableStringss=newSpannableString("abc");Drawabled=getResources().getDrawable(R.drawable.icon32);......