设置默认区 - 避免',新{面积=""}`在网站上的每一个环节上 [英] Set default area - Avoiding `, new {area = ""}` on each link on the site

查看:183
本文介绍了设置默认区 - 避免',新{面积=""}`在网站上的每一个环节上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code是母版页里面:

 <李>< A HREF =<%= Url.Action(行动,控制器)%>>主要网站的链接和LT; / A&GT ;< /李>
&其中;丽>&所述; A HREF =&其中;%= Url.Action(AreaAction,AreaController,新的{面积=区域})%>中>所在区域链路所述; / a取代;&其中; /李>
 

所有环节的工作很好,直到我将在区链接。当我去那里的主要区域的所有路由都不起作用。

要解决这个问题,我可以用这样的:

 <李>< A HREF =<%= Url.Action(行动,控制器,新{面积=})%>中>主要网站的链接和LT; / A>< /李>
 

我的问题是,有没有办法避免,新{面积=} 每次在主站点链接?

它很讨厌网站上的每一个环节上都没有了。

解决方案

URL操作是相对于链接的位置。因此,新{面积=} 不告诉Url.Action电话,有没有面积,它告诉它使用根区 。如果省略新{面积=} 从Url.Action调用它会尝试创建一个网址为当前在指定控制器内的指定动作面积(以下简称区都是你的情况)。

因此​​,如果想从一个分区链接到根区域是无法避免的。

This code is inside the master page:

<li><a href="<%=Url.Action("Action", "Controller") %>">Main site link</a></li>
<li><a href="<%=Url.Action("AreaAction", "AreaController", new {area = "Area"}) %>">Area link</a></li>

All the links works good till I'm going to the Area Link. When I go there all the routes of the main area don't work.

To fix that I can use this:

<li><a href="<%=Url.Action("Action", "Controller", new {area = ""}) %>">Main site link</a></li>

My question is, is there a way to avoid , new {area = ""} on every link in the to the main site?

Its very annoying to have this on every link on the site.

解决方案

Url actions are relative to the location of the link. So new {area = ""} is not telling the Url.Action call that there is no area, it's telling it to use the root area. If you omit new {area = ""} from the Url.Action call it will try to create a url for the specified action within the specified controller within the current area (the "Area" are in your case).

Therefore it is unavoidable if you want to link from a subarea to the root area.

这篇关于设置默认区 - 避免',新{面积=&QUOT;&QUOT;}`在网站上的每一个环节上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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