JavaScript在Editor上切换为不回发

时间:2019-05-31 18:03:54

标签: javascript c# asp.net-mvc-5 entity-framework-6

我有一个创建表单,在该表单中有一个DropdownListFor,如果单击标签,它将切换到隐藏的EditorFor

存在两个问题:

  1. 当尝试回发输入到文本框中的值时,SQL表中没有任何值
public static String reverse(String str)
{
    Stack<Character> stack = new Stack<>();
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < str.length(); i++)
        stack.push(str.toCharArray()[i]);
    }


    while(!stack.isEmpty()){
         sb.append(stack.pop());
    }

    return sb.toString();
}

我怀疑是因为JavaScript?

  1. 如果我使用
 @Html.EditorFor(model => model.StaffName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Name Here" } })

我同时显示StaffID和StaffName文本框,但是如果我使用

model => model.StaffName,

我只出现StaffName文本框。两种方式都不会发回表格

查看代码段:

model => model.StaffName.StaffName,

Javascript片段:


                      <div class="form-group"> 
                                <label id="lbltipAddStaff">Select Staff Member:</label> <label id="lbltipAddStaff2" style="display:none;">Enter Staff Member:</label>   <label style="float: right;"><i class="myClass fa fa-edit" id="staff"></i></label>
                                <div id="Staff">
                                    @Html.DropDownListFor(model => model.StaffID, ViewBag.StaffList as SelectList, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.StaffID, "", new { @class = "text-danger" })
                                </div>
    <div class="js-staff" style="display:none;">
        @Html.EditorFor(model => model.StaffName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Name Here" } })
        @Html.ValidationMessageFor(model => model.StaffName, "", new { @class = "text-danger" })
    </div>

控制器:


     $(document).ready(function () {
                $("#staff").click(function () {
                    $("#Staff").toggle();
                    $(".js-staff").toggle();
                    $('#lbltipAddStaff').toggle();
                    $('#lbltipAddStaff2').toggle();
                });
            });

0 个答案:

没有答案