我是MVC的新手。有人能解释Html.ActionLink和Ajax.ActionLink的区别吗?
发布于 2016-12-14 16:25:16
基本上都工作得很好。它们之间的主要区别是-
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,我们指定要调用哪个控制器的操作方法,并指定如何处理从action方法返回的响应。
@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
https://stackoverflow.com/questions/41147134
复制相似问题