带有图像的 MVC3 ActionLink(但没有 MvcFutures)?
我想知道是否有人知道是否可以使用任何“开箱即用”的 ASP.NET MVC3 帮助程序来生成“链接按钮”...我目前使用以下内容:
<a class="button" title="My Action" href="@Url.Action("MyAction", "MyController", new { id = item.Id })">
<img alt="My Action" src="@Url.Content("~/Content/Images/MyLinkImage.png")" />
</a>
我试图避免使用 MvcFutures,但即使如果我能够使用它们,我认为也没有一个扩展方法可以实现这一点。 (我相信这种情况下的解决方案是滚动自定义帮助程序如此处所示)
最后,这篇文章也有一个通过CSS处理这个问题的好主意,但这不是我要问的......
I was wondering if anyone knows if it possible to use any of the "out of the box" ASP.NET MVC3 helpers to generate a "link button"...I currently use following:
<a class="button" title="My Action" href="@Url.Action("MyAction", "MyController", new { id = item.Id })">
<img alt="My Action" src="@Url.Content("~/Content/Images/MyLinkImage.png")" />
</a>
I am trying to avoid using MvcFutures, but even if I was able to use them, I don't think there is a extension method it there that will accomplish this either. (I believe solution in this case would be to roll custom helper as seen here)
Finally, this post also has a good idea to handle this via CSS, but that is not what I am asking...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用以下方法生成操作链接:
请注意,GetAttributeString 方法依赖于 Fasterflect 库来使反射任务变得更容易,但如果您不想采用额外的依赖项,则可以将其替换为常规反射。
图像帮助器扩展曾经是 MvcContrib 的一部分,但似乎已被删除,很可能是因为该功能现在内置于 MVC 中。无论如何,为了完整性,我将其包含在下面:
I am using the following to generate action links:
Note that the GetAttributeString method relies on the Fasterflect library to make reflection tasks easier, but you can replace that with regular reflection if you prefer not to take the additional dependency.
The Image helper extension used to be part of MvcContrib but appears to have been removed, most likely because the functionality is now built in to MVC. Regardless, I've included it below for completeness:
你的片段看起来相当不错。您应该将其包装在通用 html 帮助程序中,然后就到此为止了。我确信您的应用程序还有其他比挑剔 UI 助手更有趣的方面:)
The snippet you have looks quite good. You should wrap it in a general-purpose html helper and call it a day. I'm sure there are other more interesting aspects to your application than nit picking about UI helpers :)
检查此 Stephen Walther 的博客文章,其中包含 HTML 扩展方法的示例
Check at the bottom of this blog post for an example with HTML extension methods from Stephen Walther