ActionMethod is gone :(

Last post 09-13-2008 12:21 PM by timtas. 4 replies.

Sort Posts:

  • ActionMethod is gone :(

    09-03-2008, 8:21 PM

     So, I just upgraded to preview 5, and now my filters are broken... One of my filters makes sure that the url contains "www" (for search engine consistency) and it uses the ActionMethod.Name property to make sure its redirecting to the proper action. Alas, the ActionMethod is now gone, so I don't know what I should use to find out what action was being accessed, or if it's even possible...

    If anyone has any ideas, I would appreciate them.

    Thanks in advance!

  • Re: ActionMethod is gone :(

    09-03-2008, 8:39 PM
    • Member
      4 point Member
    • flukus
    • Member since 02-21-2008, 5:48 AM
    • Posts 2
    I'me having this problem to. I need to filter on ActionMethod.Name and can't see a way to do it in preview 5.
  • Re: ActionMethod is gone :(

    09-04-2008, 3:56 AM
    Answer
    • Contributor
      4,374 point Contributor
    • levib
    • Member since 07-23-2007, 7:50 PM
    • Redmond, WA
    • Posts 770
    • AspNetTeam

    The ActionMethod property is gone per the discussion at http://forums.asp.net/p/1301069/2538397.aspx.  If you need to access the controller name or the action name and you're using standard MVC naming conventions for routes, you can access them from the filter context via RouteData.Values["controller"] and RouteData.Values["action"].

  • Re: ActionMethod is gone :(

    09-13-2008, 11:42 AM
    • Member
      24 point Member
    • timtas
    • Member since 11-05-2005, 10:23 AM
    • Posts 27

    Yesterday I discovered this breaking change.  I have made a workaround like so:

    var method = filterContext.Controller.GetType()
    .GetMethod(filterContext.RouteData.Values["action"].ToString());

    This feels really yucky and in fact will break if I ever want to use the AcceptVerbs attribute to translate routes into differently named methods.  Does anyone know a more sure way to do this?

    In case anyone is wondering, "why do you want the method anyway," I will explain.  My site has a main menu and I need to always know which menu item represents the current context.  To achieve this I set a filter attribute for each method that identifies its "menu context."  To get the attrubute I need to know the current executing method.  Maybe there is some other (better?) way to achieve this?

  • Re: ActionMethod is gone :(

    09-13-2008, 12:21 PM
    • Member
      24 point Member
    • timtas
    • Member since 11-05-2005, 10:23 AM
    • Posts 27

    Never mind about my question of a better way to do this.  I have found it.  Actually I had a a filter attribute on the class, SetMainMenu, and a normal attribute on the methods, MenuContext("Products").  SetMainMenu reflected on the calling method to get the MenuContext attribute and setup the menu correctly. 

    Now MenuContext is a filter attribute which then comes behind SetMainMenu and disables the the current menu item based on its key.  No need for reflection.  A better approach.

Page 1 of 1 (5 items)