In a controller action I want to build some url's and the action is called
from AJAX.
I have some problems to build the url's.

In NavigationController:

public IEnumerable<NavigationDisplay> GetMenu()
{
  //build url for FooController.Index
  //build url for BarController.Index
  //and so on
}

1. It seems that Controller.Context is not set when request is AJAX. Is
there any way to get it? This means that I can't do this in GetMenu:
var urlHelper = new UrlHelper(Context);
var url = urlHelper.For(DictHelper.Create(new string[] {"controller=Foo",
"action=index"}));

2. When I elaborated a little bit with the code in point 1 (in a none ajax
contoller action) I saw that it takes the area name from _current_
controller, which is different from area name for FooController. I'm
thinking of doing something like this instead (but maybe there is already a
way?):

private static string UrlFor<T>(string action)
  where T : IController
{
  var descriptor = ControllerInspectionUtil.Inspect(typeof (T));
  string url;
  if (string.IsNullOrEmpty(descriptor.Area))
  {
    url = string.Format("/{0}/{1}", descriptor.Name, action);
  }
  else
  {
    url = string.Format("/{0}/{1}/{2}", descriptor.Area, descriptor.Name,
action);
  }
  return url;
}

What is the recommended way to build url's for controllers (with area, name
and action)?

/martin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to