在MVC Ajax.ActionLink传递多个参数 [英] Passing multiple parameters in an MVC Ajax.ActionLink

查看:379
本文介绍了在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 可以包含一个匿名词典为将被传递到操作的各种参数:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆