asp.net mvc:如何进行图像映射?

发布于 2024-08-03 23:17:53 字数 635 浏览 12 评论 0原文

如何在 ASP.NET MVC 中构建图像映射?供参考:

<map id='headerMap'>
    <area shape='rect' href="Default.aspx" coords='300,18,673,109' />
</map>

markus 的一个不相关问题的答案的一个答案是类似的:

<a href="<%= Url.RouteUrl("MyRoute", new { param1 = "bla", param2 = 5 }) %>">
   put in <span>whatever</span> you want, also <img src="a.gif" alt="images" />.
</a>

抱歉,如果这是多余的。我的研究表明这可能是版本 2 mvc 答案。寻找类似于 Html.ActionLink 的内容(如果存在)。显然,我可以按名称引用路由并使用 Url.RouteUrl 发送参数,但这是处理它的事实上的方法吗?

谢谢

How in ASP.NET MVC would I construct an image map? For ref:

<map id='headerMap'>
    <area shape='rect' href="Default.aspx" coords='300,18,673,109' />
</map>

One answer of an answer of an unrelated question by markus is something similar:

<a href="<%= Url.RouteUrl("MyRoute", new { param1 = "bla", param2 = 5 }) %>">
   put in <span>whatever</span> you want, also <img src="a.gif" alt="images" />.
</a>

Sorry if this is redundant. My research indicated that this may be a version 2 mvc answer. Looking for something similar to Html.ActionLink if it exists. Obviously, I could reference the route by name and send in the parameters using that Url.RouteUrl, but is this the defacto way to handle it?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

追我者格杀勿论 2024-08-10 23:17:53

您必须自己创建 HTML...查看在经典 asp.net 中渲染的 html,使用:

<map id='headerMap'>
    <area shape='rect' href="Default.aspx" coords='300,18,673,109' />
</map>

然后在您自己的 asp.net mvc 视图中模仿,用您的 Url 替换地图的任何 href .RouteUrl 调用。

例如,

<map id="mymap" name="mymap">
    <area href="<%= Url.RouteUrl("MyRoute", new { param1 = "foo", param2 = 5 }) %>" alt="HTML and CSS Reference" shape="rect" coords="5,5,95,195">
    <area href="<%= Url.RouteUrl("MyRoute", new { param1 = "bar", param2 = 3 }) %>" alt="Design Guide" shape="rect" coords="105,5,195,195">
</map>
<image src="sitemap.gif" alt="Site map" "usemap"="#mymap" width="300" height="200">

查看不同的 Url.RouteUrl() 重载和/或 UrlHelper 方法,看看哪一个最适合您的情况。

一旦您解决了这个问题,我的建议是将区域链接的创建封装到 HtmlHelper 扩展中。

You'll have to create the HTML yourself... have a look at the html that is render in classic asp.net using:

<map id='headerMap'>
    <area shape='rect' href="Default.aspx" coords='300,18,673,109' />
</map>

Then mimic that in your own asp.net mvc view replacing any of the hrefs for the map with your Url.RouteUrl calls.

E.g.

<map id="mymap" name="mymap">
    <area href="<%= Url.RouteUrl("MyRoute", new { param1 = "foo", param2 = 5 }) %>" alt="HTML and CSS Reference" shape="rect" coords="5,5,95,195">
    <area href="<%= Url.RouteUrl("MyRoute", new { param1 = "bar", param2 = 3 }) %>" alt="Design Guide" shape="rect" coords="105,5,195,195">
</map>
<image src="sitemap.gif" alt="Site map" "usemap"="#mymap" width="300" height="200">

Have a look at the different Url.RouteUrl() overloads and/or UrlHelper methods to see which one suits your situation the best.

Once you've sorted that out, my recommendation would be to encapsulate the creation of you area links into a HtmlHelper extension.

泅人 2024-08-10 23:17:53

我可以替换以下内容并且效果很好:

html example:

<map id='headerMap'>
   <area shape='rect' href="Default.aspx" coords='300,18,673,109' />
</map>

mvc4 example

<map id='headerMap'>
    <area shape="rect" [email protected]("Default", "Home") coords="300,18,673,109">
</map>

I was able to substitute the following and it worked just fine:

html example:

<map id='headerMap'>
   <area shape='rect' href="Default.aspx" coords='300,18,673,109' />
</map>

mvc4 example

<map id='headerMap'>
    <area shape="rect" [email protected]("Default", "Home") coords="300,18,673,109">
</map>
深海夜未眠 2024-08-10 23:17:53

另一种选择是使用 C# 构建图像映射。以下链接提供了一些帮助程序方法,可从视图/控制器中的代码创建图像映射:

http://www.avantprime.com/articles/view-article/9/asp.net-mvc-image-map-helper

编辑:尝试http://web.archive.org/web/20110728032820/http://www.avantprime.com/articles/view-article/9/asp.net-mvc-image -map-helper 获取原始链接的存档版本。

Another option is to construct your image map with c#. The following link provides some helper methods that creates an image map from code within your view / controller:

http://www.avantprime.com/articles/view-article/9/asp.net-mvc-image-map-helper

Edit: Try http://web.archive.org/web/20110728032820/http://www.avantprime.com/articles/view-article/9/asp.net-mvc-image-map-helper for an archived version of the original link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文