从JQuery自动完成向ASP.Net MVC2操作传递参数

从JQuery自动完成向ASP.Net MVC2操作传递参数,jquery,asp.net,asp.net-mvc-2,autocomplete,Jquery,Asp.net,Asp.net Mvc 2,Autocomplete,我试图将JQuery的自动完成插件中的2个参数传递给ASP.NETMVC2操作,请参见下面的脚本。控制器名为EntityController,操作名为AddSharedUser,包含2个字符串,请参见下面复制的操作。当我试图运行它时,它试图将AddSharedUser作为单个参数传入,但失败了。知道我哪里出错了吗 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Sy

我试图将JQuery的自动完成插件中的2个参数传递给ASP.NETMVC2操作,请参见下面的脚本。控制器名为EntityController,操作名为AddSharedUser,包含2个字符串,请参见下面复制的操作。当我试图运行它时,它试图将AddSharedUser作为单个参数传入,但失败了。知道我哪里出错了吗

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<UI.Models.FormModel.EntitySharedUserContainer>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Edit Entity Shared Users
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Entity - <%= Model.EntityName%>, Edit Shared Users</h2>
<ul class="entity-shared-users">
<% foreach (var item in Model.SharedUsersList)
   { %>
           <li>
           <%: item.Name%>
           <%: Html.ActionLink("Remove", "RemoveSharedUser", "Entity", 
                new { id = Model.EntityId, CustId = item.CustId }, null)%>
           </li>
<% } %>
</ul>
<form id="search_for_entity_user" method="get" action="<%=  Url.Action("AddSharedUser",     "Entity") %>">
    <label for="term">Add Shared User:</label>
    <%= Html.TextBox("term")%>
</form>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="Notify" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="PageTitle" runat="server">
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="JavaScriptContent" runat="server">

<script type="text/javascript">
$(document).ready(function () {
    $("form#search_for_entity_user input#term").autocomplete({
        source: '<%= Url.Action("GetEntitySharedUsers", "Search") %>',
        delay: 200,
        minLength: 3,
        select: function (event, ui) {
            $.post('<%= Url.Action("AddSharedUser", "Entity") %>',
            { id: '42',  name: 'Russ' },
            function (data) { alert("x"); })
        }
    });
});
</script>

</asp:Content>

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddSharedUser(string id, string name)
{
    //Trying to use the parameters here

    return View();
}

当通过jquery/ajax发布时,您必须发布为

'<%= Url.Action("AddSharedUser", "Entity") %>' + 'id=42&name=Russ'
或者尝试在UrlAction中指定参数

'<%= Url.Action("AddSharedUser", "Entity", new { id = "42", name = "Russ" }) %>'

柱体是什么样子的?我看不出你的代码有什么问题。从你的问题中,我不明白什么参数被发送到动作中,什么是错误的。Darin,我不确定你到底想要什么,所以我将整个页面复制到了帖子中。
'<%= Url.Action("AddSharedUser", "Entity", new { id = "42", name = "Russ" }) %>'