Asp.net mvc 4 ASP.NET MVC 4-ListBoxFor,在ActionLink中发送selectedValue

Asp.net mvc 4 ASP.NET MVC 4-ListBoxFor,在ActionLink中发送selectedValue,asp.net-mvc-4,razor,selectedvalue,html.actionlink,html.listboxfor,Asp.net Mvc 4,Razor,Selectedvalue,Html.actionlink,Html.listboxfor,我有一张模特的名单。我想检索listBoxSelectedValue,并将其发送到我的操作链接中进行编辑 我的看法是: @using (Html.BeginForm()) { @Html.ListBoxFor(a => a.SelectedApplis, new SelectList(ViewBag.Applis,"ID","Name", Model.SelectedApplis))<br/> @Html.ActionLink("Add","Create","A

我有一张模特的名单。我想检索listBoxSelectedValue,并将其发送到我的操作链接中进行编辑

我的看法是:

@using (Html.BeginForm())
{
    @Html.ListBoxFor(a => a.SelectedApplis, new SelectList(ViewBag.Applis,"ID","Name", Model.SelectedApplis))<br/>
    @Html.ActionLink("Add","Create","Application")<br/>
    @Html.ActionLink("Edit","Edit","Application", null, new { listAppId = Model.SelectedApplis})<br/>
    @Html.ActionLink("Delete","Delete","Application")<br/>
}  
在我的应用程序控制器中:

    public ActionResult Edit(ListBoxApplication listAppId)
    {
        // I WANT TO RETRIEVE MY listAppId HERE, but it is always 'null'
        return View();
    }
所以我认为我的问题在于actionLink:

@Html.ActionLink("Edit","Edit","Application", null, new { listAppId = Model.SelectedApplis})
Me编辑方法不是实际的控制器主/索引。我需要将操作链接中列表框的selectedValue发送到应用程序/编辑

listAppId始终为“null”。它无法检索值。。。我的actionLink有错误吗


感谢您的帮助

我不相信操作链接会触发对服务器的回发。请尝试以下方法:

    @Html.ActionLink("Delete","Delete","Application")<br/>
    @Html.ActionLink("Add","Create","Application")<br/>

    @using (Html.BeginForm("Detail","Application"))
    {
        @Html.ListBoxFor(a => a.SelectedApplis, new SelectList(ViewBag.Applis)) //not sure what the other params you had here were for, but it should work like this
        <br/>
        <input type="submit" name="Edit" value = "Edit"/>
        @*added in response to comment*@
        <input type="submit" name="Delete" value = "Delete"/>
        <input type="submit" name="Add" value = "Add"/>
    }  

从您发布的代码来看,ApplicationModels.GetListApplications似乎返回null。我填写了我的listApplications。它们显示在我的列表框中。所以GetListApplications正在运行。所以Edit需要一个ListBoxApplication,而您正在发送一个IEnumerable?这就是我看到的吗?对不起,我之前在测试输入,但忘记在我的帖子中更改它。。。我的编辑方法需要一个IEnumerable。谢谢,我想你是对的,我们不能在一个表单中有多个操作链接。。。但你说的是多种形式。如何为每个actionlink提供3个表单,并且只有一个列表框?列表框只有一种形式否?或者有其他方法吗?好的,有两种方法,一种方法是让所有的动作链接变成提交按钮,参见上面的代码,并将值更改为想要显示的文本。现在,如果你给他们每个人一个名字,并将这个名字作为参数添加到你的控制器中,作为字符串或bool,那么你就可以知道是哪个按钮被点击了。给我一分钟我会在回复中模拟一个控制器
@Html.ActionLink("Edit","Edit","Application", null, new { listAppId = Model.SelectedApplis})
    @Html.ActionLink("Delete","Delete","Application")<br/>
    @Html.ActionLink("Add","Create","Application")<br/>

    @using (Html.BeginForm("Detail","Application"))
    {
        @Html.ListBoxFor(a => a.SelectedApplis, new SelectList(ViewBag.Applis)) //not sure what the other params you had here were for, but it should work like this
        <br/>
        <input type="submit" name="Edit" value = "Edit"/>
        @*added in response to comment*@
        <input type="submit" name="Delete" value = "Delete"/>
        <input type="submit" name="Add" value = "Add"/>
    }  
public ActionResult Detail(ListBoxApplication listAppId, bool Edit, bool Add, bool Delete)
{
    if(//check your bools here){
    }
    return View();
}