asp.net-mvc 在 MVC Ajax.ActionLink 中传递多个参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2595830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:14:51  来源:igfitidea点击:

Passing multiple parameters in an MVC Ajax.ActionLink

asp.net-mvcparameters

提问by mwright

I am using an Ajax.ActionLink to call an Action in a Controller, nothing special there. I want to pass two parameters to the Action. Is this possible using an Ajax.ActionLink? I thought that it would just be a matter of including multiple values in the AjaxOptions:

我正在使用 Ajax.ActionLink 来调用控制器中的操作,没有什么特别之处。我想将两个参数传递给 Action。这可以使用 Ajax.ActionLink 吗?我认为这只是在 AjaxOptions 中包含多个值的问题:

<%= Ajax.ActionLink("Link Text",
    "ActionName",
    "ControllerName",
    new { firstParameter = firstValueToPass, secondParameter = secondValueToPass },
    new AjaxOptions{ UpdateTargetId = "updateTargetId"} )%>

Is it possible to pass multiple parameters?

是否可以传递多个参数?

Where is a good place to learn more about the AjaxOptions?

哪里是了解有关 AjaxOptions 的更多信息的好地方?

回答by Ben Scheirman

Depending on which overload you choose for Ajax.ActionLink, the parameter called routeDatacan contain an anonymous dictionary for the various parameters that will be passed to the action:

根据您为 Ajax.ActionLink 选择的重载,调用的参数routeData可以包含将传递给操作的各种参数的匿名字典:

<%= Ajax.ActionLink("Link Text",
    "DoSomething",
    "AwesomeController",
    new { foo = "foo1", bar = "bar1" },
    new AjaxOptions{ UpdateTargetId = "updateTargetId"} )%>

This doesn't have anything to do with the AjaxOptionsparameter, which gives you some control about the behavior of the request/response.

这与AjaxOptions参数无关,它使您可以对请求/响应的行为进行一些控制。

public class AwesomeController
{
   public ActionResult DoSomething(string foo, string bar)
   {
      /* return your content */
   }
}