.NET MVC Call method on different controller

前端 未结 7 1397
Happy的楠姐
Happy的楠姐 2020-11-30 06:26

Can anybody tell me how to call a method on a different controller from within an action method? I don\'t want to redirect. I want to call a method on a different controller

7条回答
  •  迷失自我
    2020-11-30 06:59

    I was looking for the same thing, but seriously people, why the need to write such complicated answers.

    Here's a post that will answer it very simply: Using Html.ActionLink to call action on different controller

    Basically you just have to use this overload of the actionlink: ActionLink(HtmlHelper, String, String, String, Object, Object)

    So you will have: ActionLink("linkText", "actionName", "controllerName", routeValues, htmlAttributes)

    If you don't have any routeValues (which are the Inputs for the Action) or htmlAttributes, you have to set them as null.

    Here's an example call: @Html.ActionLink("Add New Student", "Create", "Student", null, new { @class = "btn btn-primary" })

提交回复
热议问题