【问题标题】:Passing multiple parameters in an MVC Ajax.ActionLink在 MVC Ajax.ActionLink 中传递多个参数
【发布时间】:2010-04-07 20:52:31
【问题描述】:

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

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

是否可以传递多个参数?

哪里是了解更多关于 AjaxOptions 的好地方?

【问题讨论】:

    标签: asp.net-mvc parameters


    【解决方案1】:

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

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

    这与AjaxOptions 参数没有任何关系,它可以让您对请求/响应的行为进行一些控制。

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

    【讨论】:

    • 如何生成类似AwesomeController/DoSomething/foo1/bar1而不是AwesomeController/DoSomething?foo=foo1&amp;bar=bar1的路径
    • 如何生成这样 AwesomeController/DoSomething/foo1/bar1 的路径
    猜你喜欢
    • 2011-10-05
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多