HTML.ActionLink VS Url.Action在ASP.NET剃刀 [英] HTML.ActionLink vs Url.Action in ASP.NET Razor

查看:90
本文介绍了HTML.ActionLink VS Url.Action在ASP.NET剃刀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有VS Url.Action 之间的 HTML.ActionLink 任何区别或者他们做的只是两种方式同样的事情?

Is there any difference between HTML.ActionLink vs Url.Action or they are just two ways of doing the same thing?

当我应该preFER一个比其他?

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,新{ID =123})生成:

/somecontroller/someaction/123

还有 Html.Action 它执行一个孩子控制器动作。

There is also Html.Action which executes a child controller action.

这篇关于HTML.ActionLink VS Url.Action在ASP.NET剃刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆