我正在使用 jquery.autocomplete 插件,当它发出 Ajax 请求时,它给了我 HTTP 错误代码 500,并且消息正文显示路径中的非法字符。
我正在使用 MVC3,并且我已将 javascript 代码从视图移动到一个单独的脚本文件,该脚本文件在我的 _layout.cshtml 文件中引用。在我移动我的 javascript 之前它可以工作,但现在它没有,我不明白为什么。
自动完成.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: <strong>@Context.User.Identity.Name</strong>
</span>
</div>
<nav>
<ul id="menu">
@Html.ActionLink("Home", "Index", "Home")  
@Html.ActionLink("User Management", "Index", "UserManager")  
@Html.ActionLink("User Status", "Index", "UserStatus")  
@Html.ActionLink("Email Distibution List", "Index", "EmailDistributionList")  
@Html.ActionLink("Email User Details", "Index", "EmailUserDetails")  
</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);
}