在我的应用程序中,我有一个控制器消息
public class MessageController : BaseController
{
...
}
BaseController 是一个抽象类并包含一个方法 FindUserForMessages。此方法必须在此控制器中,因为此“BaseController”在 3 个类似的 Web 应用程序中用作父级,并包含所有应用程序的通用功能。
public abstract class BaseController : Controller
{
[Authorize]
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult FindUser(string userName, int maxRecords)
{
try
{
return Json(new JsonResult()
{
IsError = false,
ErrorMessage = string.Empty,
Data = (from u in AccountModel.FindUser(userName, false).Take(maxRecords)
select new
{
UserName = u.UserName,
UserId = u.ProviderUserKey,
IsOnlien = u.IsOnline
})
});
}
catch (Exception ex)
{
...
}
}
}
我想将此方法用于 JqueryUI AutoComplete 小部件的来源。我正在尝试通过 Ajax 调用此方法:
$("#txtQuickMessageSendTo").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Message/FindUser",
data: {
userName: request.term,
maxRecords: 10
},
success: function (resultObj) {
if (resultObj.IsError) {
handleAjaxError(null, null, null, null, resultObj.ErrorMessage, null);
return;
}
else {
response($.map(data.Data, function (item) {
return {
label: item.UserName,
value: item.ProviderUserKey
}
}));
}
}
});
},
minLength: 2,
select: function (event, ui) {
//log(ui.item ? "Selected: " + ui.item.label : "Nothing selected, input was " + this.value);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
我使用 Fiddler2 进行 Web 调试,请求中都是参数(用户名和 maxRecords),但服务器抛出错误:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Message/FindUserForMessages
参数是好的,但为什么我不能调用这个方法?
感谢