开发者

Passing multiple parameters in an MVC Ajax.ActionLink

开发者 https://www.devze.com 2022-12-25 19:26 出处:网络
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 jus

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 includi开发者_如何学Cng 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?

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


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"} )%>

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 */
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消