如何更改 ASP.NET MVC 中链接的呈现?
我们的设计师为需要添加 的应用程序设计了按钮样式。 内的标签我们的链接的标签。
在 ASP.NET 中,我们通过为链接按钮添加 App_Browsers 条目来实现这一点。
我将如何在 ASP.NET MVC 中执行此操作?
我考虑过创建我自己的版本的所有各种 HTML 帮助器函数来创建 ActionLinks 和 RouteLinks,但这似乎是一种相当“蛮力”的做事方式。
有没有一种优雅的方式来做到这一点?
我知道我们可以编写一些简单的 jQuery 来做到这一点,但我们宁愿首先让标记正确地从服务器中出来。
Our designers have come up with button styles for an application which require the addition of <span> tags inside the <a> tags of our links.
In ASP.NET we implemented this by adding an App_Browsers entry for Link Buttons.
How would I go about doing this in ASP.NET MVC?
I've contemplated creating my own versions of all of the various HTML helper functions for creating ActionLinks and RouteLinks but this seems to be quite a 'brute force' way of doing things.
Is there a nice elegant way of doing it?
I know we could write some simple jQuery to do it, but we'd rather have the markup coming out of the server correctly in the first place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上,我认为编写一个新的助手正是我所要走的路。在我看来,这正是它们存在的目的,而且也使得它们非常可重复使用。
Actually I think writing a new helper is exactly the way I would go. Seems to me that that's exactly what they are there for and it makes them very re-usable too.
您始终可以编写一个扩展方法,该方法将另一个(内置方法之一)作为参数,并将
包裹在链接文本周围在调用它之前。使用 lambda 应该很容易做到...
并调用它:
(此代码直接输入到 SO 的答案字段中 - 我什至没有检查它以确保它可以编译。所以请耐心等待如果第一次尝试不起作用...)
You could always write one extension method, that takes another one (one of the built-in ones) as an argument, and wrappes the
<span>
around your link text before calling it. It should be quite easy to do with lambdas...And to call it:
(This code is typed directly into the answer field of SO - I haven't even checked it to make sure it compiles. So bear with me if it doesn't work on the first try...)