Html.ActionLink和Ajax.ActionLink之间的区别

时间:2016-12-14 16:09:02

标签: asp.net-mvc

我是MVC的新手。任何人都可以解释Html.ActionLink和Ajax.ActionLink之间的区别吗?

1 个答案:

答案 0 :(得分:9)

基本上两者都完美无缺。它们之间的主要区别是 -

Html.ActionLink - Html.ActionLink在视图上创建一个新链接,当用户点击链接时,它不直接链接到视图,它将通过MVC路由。它将通过路由映射到一个动作方法。

Html.ActionLink(test.login, 
                "Action",   //  ActionMethod Name
                "Login",  // Controller Name.
                new { person.loginId}, //  Route arguments.
                null  // <-- htmlArguments .. which are none. You need this value
                      //     otherwise you call the WRONG method ...
                      //     (refer to comments, below).
                )

Ajax.ActionLink :Ajax.ActionLink还在视图上创建了一个新链接,但是当用户单击它时,Ajax.ActionLink发送异步请求而不是导航到新URL。使用Ajax.ActionLink,我们指定要调用的控制器的操作方法,并指定如何处理从操作方法返回的响应。

@Ajax.ActionLink("Customer from Germany", // <-- Text to display
                 "Germany", // <-- Action Method Name
                 new AjaxOptions
                 {
                     UpdateTargetId="CustomerList", // <-- DOM element ID to update
                     InsertionMode = InsertionMode.Replace, // <-- Replace the content of DOM element
                     HttpMethod = "GET" // <-- HTTP method
                 })

希望它会帮助你。 要了解更多信息,请仔细阅读 Article

相关问题