将数据从JavaScript传递到MVC控制器

时间:2015-03-18 11:14:49

标签: javascript asp.net-mvc sharepoint sharepoint-2013

威康!

我将数据从JavaScript传递到MVC Controller时遇到问题。我是MVC的新手,所以我可能会错过一些东西。

$("#example").keypress(function (event) {
    var data = "example";
    $.ajax({
        url: "/example/example",
        type: "POST",
        dataType: "json",
        data: { example: data },
        success: function (example) {
            var items = "";
            $.each(data, function (i, example) {
                items += "<option>" + example + "</option>";
            });
            $("#example").html(items);
        }
    });
});

public class PeoplePickerController : BaseController
{
    // GET: PeoplePicker
    public ActionResult PeoplePicker(object data)
    {
        if (HttpContext.Request.IsAjaxRequest())
        {
            IQueryable logins = (IQueryable)QueryDatabaseForUsersAndGroups((string)data, Context.Users);

            return Json(new SelectList(example, "example"), JsonRequestBehavior.AllowGet);
        }

        return PartialView();
    }

}

数据参数始终为空。

0 个答案:

没有答案