在MVC Ajax.ActionLink传递多个参数 [英] Passing multiple parameters in an MVC Ajax.ActionLink
问题描述
我使用的是Ajax.ActionLink调用在控制器的操作,没什么特别的存在。我想两个参数传递给动作。使用Ajax.ActionLink这可能吗?我认为这将只是包括在AjaxOptions多个值的问题:
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("Link Text",
"ActionName",
"ControllerName",
new { firstParameter = firstValueToPass, secondParameter = secondValueToPass },
new AjaxOptions{ UpdateTargetId = "updateTargetId"} )%>
是否可以将多个参数传递?
Is it possible to pass multiple parameters?
在哪里是学习更多有关AjaxOptions的好地方?
Where is a good place to learn more about the AjaxOptions?
推荐答案
根据所超载您选择Ajax.ActionLink,称为参数的RouteData code>可以包含一个匿名词典为将被传递到操作的各种参数:
Depending on which overload you choose for Ajax.ActionLink, the parameter called routeData
can contain an anonymous dictionary for the various parameters that will be passed to the action:
<%= Ajax.ActionLink("Link Text",
"DoSomething",
"AwesomeController",
new { foo = "foo1", bar = "bar1" },
new AjaxOptions{ UpdateTargetId = "updateTargetId"} )%>
这不会有什么用 AjaxOptions
参数,它为您提供了有关请求/响应的行为有所控制。
This doesn't have anything to do with the AjaxOptions
parameter, which gives you some control about the behavior of the request/response.
public class AwesomeController
{
public ActionResult DoSomething(string foo, string bar)
{
/* return your content */
}
}
这篇关于在MVC Ajax.ActionLink传递多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!