与URL片段创建T4MVC的ActionLink [英] Create a T4MVC ActionLink with url fragment

查看:102
本文介绍了与URL片段创建T4MVC的ActionLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来创建一个强类型T4MVC ActionLink的,在它的哈希/英镑/片段?

Is there a way to create a strongly typed T4MVC ActionLink with a hash/pound/fragment in it?

例如,这里是链接,我想创建:

For example, here is the link I'd like to create:

<a href="/Home/Index#food">Feed me</a>

但目前还没有扩展到T4MVC对象,可以做到这一点。

But there's no extension to the T4MVC object that can do this.

<%= Html.ActionLink("Feed me", T4MVC.Home.Index()) %>

所以,我最终不得不做的就是创建一个动作,然后嵌入这种方式:

So, what I end up having to do is create an action, and then embed it that way:

<a href="<%= Url.Action(T4MVC.Home.Index()) %>"#food>Feed me</a>

这是不是非常可取的。任何人有任何意见/建议吗?

This isn't very desirable. Anyone have any ideas/suggestions?

在此先感谢

推荐答案

这样的方式是唯一一个我能想到的,感觉(我)略高于手动编写主播更好:

This kind of approach is the only one i can think of that feels (to me) slightly better than writing anchor manually:

${Html.ActionLink("Feed me", T4MVC.Home.Index(), Fragment: "food")}

除了火花视图引擎 - 它的成本1历久弥新的HtmlHelper扩展方法和放大器;命名参数。

Apart from spark viewengine - it costs 1 good old htmlhelper extension method & named parameters.

我认为这是不具备的默认视图引擎?我决定写一个快速扩展的ActionLink的,但它不是优雅,而且我也喜欢的任何解决方案,以提供给他人T4MVC的未来版本。

I assume that this isn't available in the default viewengine? I've decided to write a quick extension for the ActionLink, but it's not elegant, and I would have liked any solution to be available to others in future versions of T4MVC.

星火替换了&LT;%=%>用$ {}。刚才所说的,因为我preFER它(如果你强调code优雅你应该尝试)。 C#4.0需要才能使用命名的参数。

Spark replaces <%=%> with ${}. Mentioned just because I prefer it (You should try it if You emphasize code elegance). C# 4.0 is required in order to use named parameters.

这是因为我想避免丢失信息,在该参数的食的说法地图。

That's because I would like to avoid losing information to which parameter "food" argument maps.

和是的,我强烈的Mattias Jakobsson着同意。

And yeah, i strongly agree with Mattias Jakobsson.

这篇关于与URL片段创建T4MVC的ActionLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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