Javascript 如何防止Web基本区域破坏jquery?

Javascript 如何防止Web基本区域破坏jquery?,javascript,jquery,ajax,razor-2,web-essentials,Javascript,Jquery,Ajax,Razor 2,Web Essentials,我使用的是WebEssentials2012和VisualStudio2012以及RazorWeb页面,而不是MVC 我有一个jquery ajax,如下所示: $("#test1").ready(function () { var test = { "loadTestList": "loadTestList" }; function loadTestList(response) { var ddlTest = $('#test1'); ddl

我使用的是WebEssentials2012和VisualStudio2012以及RazorWeb页面,而不是MVC

我有一个jquery ajax,如下所示:

$("#test1").ready(function () {

    var test = { "loadTestList": "loadTestList" };

    function loadTestList(response) {
        var ddlTest = $('#test1');
        ddlTest.empty();

        ddlTest.append(
                $("<option></option>").text('All').val('All')
            );
        for (var i = 0; i < response.length; ++i) {
            ddlTest.append(
                $("<option></option>").text(response[i].TestName).val(response[i].TestName)
            );
        }
    }

    $.ajax({
        url: "../Controllers/TestController.cshtml",
        data: test,
        type: "POST",
        dataType: "json",
        success: function (response) {
            loadTestList(response);
        },
        error: function () {
            console.log("Sorry, there seems to be a problem contacting the Test server.");
            console.log(response.responseStatus);
            console.log(response.responseText);
        }
    });
});
@* Controllers/TestController.cshtml *@
@{    
    if (IsPost && Request["loadTestList"] != null)
    {
        var tests = new TestRepository(new TestContext());
        var testslist = tests.Load();

        Json.Write(testslist, Response.Output);
    }
}@
是的,这也行

但当我这么做的时候:

@{    
    <!-- #region TestMe -->
    if (IsPost && Request["loadTestList"] != null)
    {
        var tests = new TestRepository(new TestContext());
        var testslist = tests.Load();

        Json.Write(testslist, Response.Output);
    }
    <!-- #endregion -->
}@
每次都会中断jQuery。$。ajax每次都会出错

那么有人知道防止这种情况发生的方法吗?我非常喜欢区域,但我不能让它破坏jQuery的其余部分

另外,如果我通过Json.Write传递的都是testslist,那么为什么这会首先破坏jQuery呢


注意:TestController.cshtml只有服务器端代码。完全没有HTML。

在@{}块内您可以使用标准c预编译器指令:

#region [region_name]
#endregion
里面

<script></script>
//#region [region_name]
//#endregion