简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM