gpt4 book ai didi

c# - 形成 MVC/ Controller / Action 链接的最佳实践

转载 作者:太空狗 更新时间:2023-10-30 00:24:40 24 4
gpt4 key购买 nike

我想知道在某个 Controller 上指定操作的最佳做​​法是什么。

我一直在处理的部分代码将 url 指定为:

<a href="/controller/action"/>

我通常不太喜欢这种风格。我更喜欢使用:

<a href='@Url.Action("Action", "Controller")'/>

1) 在这种情况下,为内部操作构建 URL 的最佳做法是什么?两者都有效,只是想知道哪个更好。

2) 使用一个与另一个相比有什么好处吗?

最佳答案

在这两个选项中,我认为第二个是更好的方法,因为它适用于虚拟路径/目录:

<a href='@Url.Action("Action", "Controller")'/>

不过我更喜欢使用 ActionLinks:

@Html.ActionLink("text", "action", "controller")

关于c# - 形成 MVC/ Controller / Action 链接的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22820866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com