Skitterm
Skitterm

Reputation: 4595

Passing data to controller using Ajax.ActionLink

I am trying to write a link to a partial view on the same page. Everything works, except that I am not able to pass in the needed month parameter through my ajax.actionlink syntax. I've tried using the ViewDataDictionary, but to no avail. Also, RouteValueParameter was a thought I had, but I'm trying to pass a string, not an integer id.

Below is my code in the view, followed by the method in the controller:

<td>@Ajax.ActionLink("January", "ControllerMethod", new ViewDataDictionary{{"month", "January"}}, new AjaxOptions { UpdateTargetId = "view-month" })</td>



public ActionResult ViewMonths(string month)
    {
        //some code here
        return PartialView("ViewMonths", schedule);
    }

Any ideas?

Upvotes: 3

Views: 17263

Answers (1)

Andrzej Siwek
Andrzej Siwek

Reputation: 300

Try this way

@Ajax.ActionLink("Link Text", "MyAction", "MyController", new { month = "January",  plum = "2", moreparams = "U can do this all day"}, new AjaxOptions{ UpdateTargetId = "view-month" } )

Greatings

Upvotes: 13

Related Questions