ASP.NET Razor 中的 HTML.ActionLink 与 Url.Action [英] HTML.ActionLink vs Url.Action in ASP.NET Razor
本文介绍了ASP.NET Razor 中的 HTML.ActionLink 与 Url.Action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML.ActionLink
和 Url.Action
之间有什么区别吗?或者它们只是做同一件事的两种方式?
Is there any difference between HTML.ActionLink
vs Url.Action
or they are just two ways of doing the same thing?
我什么时候应该更喜欢一个?
When should I prefer one over the other?
推荐答案
是的,有区别.Html.ActionLink
生成一个 <a href=".."></a>
标签,而 Url.Action
只返回一个网址.
Yes, there is a difference. Html.ActionLink
generates an <a href=".."></a>
tag whereas Url.Action
returns only an url.
例如:
@Html.ActionLink("link text", "someaction", "somecontroller", new { id = "123" }, null)
生成:
<a href="/somecontroller/someaction/123">link text</a>
和 Url.Action("someaction", "somecontroller", new { id = "123" })
生成:
/somecontroller/someaction/123
还有 Html.Action 执行子控制器操作.
There is also Html.Action which executes a child controller action.
这篇关于ASP.NET Razor 中的 HTML.ActionLink 与 Url.Action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文