2

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.

1 Answers1

0

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.

amurra
  • 15,221
  • 4
  • 70
  • 87
  • neither work, still getting resource cannot be found error. suggestions? – JoeShiteTheRagMan Aug 04 '11 at 17:22
  • @JoeShiteTheRagMan - Try getting rid of the `~` in your url's in your sitemap and try again. Otherwise, that should work as long as your actions are in the Home controller file. – amurra Aug 04 '11 at 18:11
  • Also turned on tracing and am getting the following which makes no sense to me at the moment... [Message: A public action method 'TestActionResult' was not found on controller 'Namespace.Controllers.HomeController'.] [Source: System.Web.Mvc]... it does exist... – JoeShiteTheRagMan Aug 04 '11 at 18:33
  • @JoeShiteTheRagMan - Remove the `Namespace.controllers' from your route and try again. Also what is the namespace that your HomeController is in? – amurra Aug 04 '11 at 18:52
  • namespace.controllers is an alias for the purpose of public posting... my HomeController is in the applicable namespace.controllers and ActionResult TestActionResult is in HomeController... I changed route to routes.MapRoute( "TestActionResult", "Home/TestActionResult", new { controller = "Home", action = "TestActionResult", area = "" } ); I get same error resource cannot be found & trace msg. – JoeShiteTheRagMan Aug 04 '11 at 19:19
  • adding ... [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)] ... to the ActionResult was the fix – JoeShiteTheRagMan Aug 04 '11 at 22:02