0

jquery.autocompleteプラグインを使用していますが、Ajaxリクエストを送信すると、HTTPエラーコード500が表示され、メッセージの本文にパスに不正な文字が含まれていることが示されます。

私はMVC3を使用しており、JavaScriptコードをビューから_layout.cshtmlファイルで参照されている別のスクリプトファイルに移動しました。JavaScriptを移動する前は機能していましたが、現在は機能しておらず、その理由がわかりません。

Autocomplete.js

$(document).ready(function () {
    alert("one");
    $("#group_name").autocomplete('@Url.Action("LookUpGroupName", "UserManager")', // Call LookUpGroupName ActionResult in UserManager Controller
        {
        dataType: 'jsonp',
        parse: function (data) {
            var rows = new Array();
            for (var i = 0; i < data.length; i++) {
                rows[i] = {
                    data: data[i],
                    value: data[i].group,
                    result: data[i].group
                }
            }
            return rows;
        },
        formatItem: function (row, i, max) {
            return row.group;
        },
        width: 300,
        highlight: false,
        multiple: false
    }); // End of autocomplete
    alert("two");
});

_Layout.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.autocomplete.custom.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.autocomplete.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/Custom/autocomplete.js")" type="text/javascript"></script>
  <link href="@Url.Content("~/Content/themes/base/jquery.ui.autocomplete.css")" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="page">
        <header>
           <div id="title" >
    <h1 style="color:Black">ALF and BRAD User Manager</h1>
</div>
<div id="logindisplay">
    <span style="color:Black; background-color:white; border-color:Black; border-style:solid; border-width:thin; text-align:right;">
        Logged in as:&nbsp<strong>@Context.User.Identity.Name</strong>
    </span> 
</div>

            <nav>
                <ul id="menu">
                    @Html.ActionLink("Home", "Index", "Home")&nbsp&nbsp
                    @Html.ActionLink("User Management", "Index", "UserManager")&nbsp&nbsp
                    @Html.ActionLink("User Status", "Index", "UserStatus")&nbsp&nbsp
                    @Html.ActionLink("Email Distibution List", "Index", "EmailDistributionList")&nbsp&nbsp
                    @Html.ActionLink("Email User Details", "Index", "EmailUserDetails")&nbsp&nbsp
                </ul>
            </nav>
        </header>
        <section id="main">
            @RenderBody()
        </section>
        <footer>
        </footer>
    </div>
</body>
</html>

意見

<!-- Declare model to be used for view -->
@model UserManager.Models.vw_UserManager_Model_Add_Users 
@{
    ViewBag.Title = "Create New User";
}
<h2>
    CreateUser</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>New User Details</legend>
        <div class="editor-label">
            @Html.LabelFor(Model => Model.salutation)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => Model.salutation)
            @Html.ValidationMessageFor(model => Model.salutation)
        </div>
       @{Html.Partial("~/Views/Partial/_AutocompleteGroupName.cshtml", this.ViewData);
}

Ajaxレスポンス

4

2 に答える 2

0

ページに含まれるスクリプトの url.action ヘルパーを使用した ASP.NET MVC jQuery オートコンプリートは、問題を解決すると信じています。http://localhost:51395/UserManager/@Url.action(%20 ... etc

@Url.action は、ファイルが外部スクリプトに移動されたときに解析されません。これは、javascript がその解析エンジンを介して実行されないためです。それはサーバー側です。

于 2012-11-09T13:24:27.517 に答える
0
window.location = '<%=@Url.Action("GetValue","TaskNew") %>';
于 2013-09-22T08:22:46.673 に答える