我不知道为什么这个Java Script代码不能在MVC中运行

时间:2016-11-08 06:08:30

标签: javascript jquery asp.net-mvc

在下拉列表中显示onchange事件调用FillSystem()发送了Ajax请求,但scopeId选择器不运行以下方法。

function FillSystem() {
    var _scopeId = $('#ScopeId').val();
    var _roleId = $('#Role_Id').val();
    $.ajax({
        url: '/Account/FillSystem',
        type: "GET",
        dataType: "JSON",
        data: { scopeId: _scopeId, roleId: _roleId },
        success: function (systems) {
            $("#SystemId").html(""); // clear before appending new list
            $.each(systems, function (i, system) {
                $("#SystemId").append(
                    $('<option></option>').val(system.System_Id).html(system.SystemName));
            });
        }
    });
}

<table class="table w3-striped w3-border w3-card-4" style="width: 65%">
    <tr>
        <td>
            Scope
        </td>
        <td>
            @Html.DropDownList("ScopeId", null,"--Please Select--", new { style = "width:250px", @onchange = "FillSystem()" })
        </td>
    </tr>
    <tr>
        <td>System</td>
        <td>
            @Html.DropDownList("SystemId", null, "--please select--", new { style = "width:250px" })
        </td>
    </tr>
</table>

1 个答案:

答案 0 :(得分:0)

你在表中使用DropDown并且可能存在多行,并且多个id同样,你的$(&#39;#ScopeId&#39;)选择器,选择带有ScopeId的第一个元素。

首先删除@onchange =&#34; FillSystem()&#34;从DropDownList,然后尝试此代码

string ss="Dear Ankit, pls verify your profile on www.abcd.com with below login details: User ID : 123 Password: 123 Team- abcd";
 Regex Re = new Regex("What Regex Here");
if(Re.IsMatch(ss))
        {
            lblmsg.Text = "Matched!!!";
        }
        else
        {
            lblmsg.Text = "Not Matched!!!";
        }