Asp.Net MVC SiteMap - siteMapNode:如何重定向到控制器 ActionResult

发布于 2024-11-28 02:02:16 字数 1283 浏览 2 评论 0原文

我有一个基于标准 xml 站点地图的简单菜单,当单击链接时,我希望它发布到没有视图/页面的控制器操作结果。当我有一个视图或页面或其他网站的网址时,我似乎没有问题,但我似乎无法直接转到所需的控制器操作结果...从那里我将做一些额外的事情以及返回/重定向等,问题是从 siteMapNode 中定义的条件/属性/元素获取适用的控制器操作结果。

适用的站点地图片段:

<siteMapNode url="~/Home/Test" title="Test SubMenu" description="Test SubMenu" roles="*"> 
  <siteMapNode url="~/Home/TestActionResult" title="Test ActionResult" description="Test ActionResult" roles="*" />     <!-- Does not work -->
  <siteMapNode url="http://www.google.com/" title="Test ActionResult" description="Test   ActionResult" roles="*" target="_blank"/>  <!-- Works -->
</siteMapNode> 

适用的控制器操作结果片段:

public ActionResult TestActionResult()
{
  ...
} 

适用的路线片段:

routes.MapRoute(
  "TestActionResult", 
  "TestActionResult", 
  new { controller = "Home", action = "TestActionResult", area = "" }, 
  new string[] { "Namespace.Controllers" }
);

我得到的唯一错误是找不到大多数无用的资源错误。

EG:

“/”应用程序中的服务器错误。

找不到资源。 描述:HTTP 404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下 URL 并确保拼写正确。

请求的 URL:/Home/TestActionResult


版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET版本:4.0.30319.225

有建议吗?

提前致谢。

I have a simple menu based on a standard xml sitemap, that when a link is clicked I want it to post to a controller actionresult that does not have a view/page. I don't seem to have a problem when I have a view or page or other website for the url but I do not seem to be able to just go to the desired controller actionresult... from there I will be doing some additional things and returning/redirecting etc., problem is getting to the applicable controller actionresult from criteria/attributes/elements defined in a siteMapNode.

applicable site map snippet:

<siteMapNode url="~/Home/Test" title="Test SubMenu" description="Test SubMenu" roles="*"> 
  <siteMapNode url="~/Home/TestActionResult" title="Test ActionResult" description="Test ActionResult" roles="*" />     <!-- Does not work -->
  <siteMapNode url="http://www.google.com/" title="Test ActionResult" description="Test   ActionResult" roles="*" target="_blank"/>  <!-- Works -->
</siteMapNode> 

applicable controller action result snippet:

public ActionResult TestActionResult()
{
  ...
} 

applicable route snippet:

routes.MapRoute(
  "TestActionResult", 
  "TestActionResult", 
  new { controller = "Home", action = "TestActionResult", area = "" }, 
  new string[] { "Namespace.Controllers" }
);

the only error i get is the mostly useless resource cannot be found error.

E.G.:

Server Error in '/' Application.

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Home/TestActionResult


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

suggestions?

thanks in advance.

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

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

发布评论

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

评论(1

卸妝后依然美 2024-12-05 02:02:16

更改您的路线以匹配它找不到的 URL(即 TestActionResult -> Home/TestActionResult):

routes.MapRoute(
  "TestActionResult", 
  "Home/TestActionResult", 
  new { controller = "Home", action = "TestActionResult" }
);

或者如果您想匹配 Home 控制器中的各种操作,请设置您的路线,如下所示:

routes.MapRoute(
      "HomeActions", 
      "Home/{action}", 
      new { controller = "Home", action = "TestActionResult" }
    );

现在 /Home/ TestActionResult 将转到 Home 控制器 TestActionResult 操作,而 /Home/Test 将转到 Home 控制器 Test 操作。

Change your route to match the URL that it can't find (ie. TestActionResult -> Home/TestActionResult):

routes.MapRoute(
  "TestActionResult", 
  "Home/TestActionResult", 
  new { controller = "Home", action = "TestActionResult" }
);

or if you want to match various actions in the Home Controller setup your route like this:

routes.MapRoute(
      "HomeActions", 
      "Home/{action}", 
      new { controller = "Home", action = "TestActionResult" }
    );

Now /Home/TestActionResult will go to the Home Controller TestActionResult action and /Home/Test will go to the Home controller Test action.

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