0

I wasn't sure how to title this question. Currently in my Razor view I have the following

@Html.ActionLink("Rank -1", "ChangeRank", new
           {
               id = item.ID,
               newRank = (item.UserRank + 1),
               PosiFilter,
               TeamFilter,
               CurrentFilter,
               userLeagueID
           })

The last set of data, the PosiFilter, TeamFilter, CurrentFilter, etc is used all over my view in different @Html.ActionLinks. Is there a way to set all of these once at the start of my page,

@{
    ViewBag.Title = "Index";
    string PosiFilter = @ViewBag.posiFilter;
    string TeamFilter = @ViewBag.teamFilter;
    string CurrentFilter = @ViewBag.CurrentFilter;
    int userLeagueID = @ViewBag.userLeagueID;

var GroupedRouteValues = PosiFilter, TeamFilter, CurrentFilter, userLeagueID
}

and then use them in an actionlink like so:

@Html.ActionLink("Rank -1", "ChangeRank", new
               {
                   id = item.ID,
                   newRank = (item.UserRank + 1),
                    GroupedRouteValues
               })

I tried playing around with @Url.Action but I couldn't figure out how to use it if I wanted to add extra route values to that particular link, yet include the routevalues fro earlier.

dave317
  • 754
  • 2
  • 12
  • 30

1 Answers1

0

I figured out a way to do this on my own. I send a string returnUrl using this.Request.RawUrl with each actionlink and then on my controller I return a redirect to returnUrl instead of Redirect to Action or Return View().

Ex of View:

@Html.ActionLink("Rank -1", "ChangeRank", new
               {
                   id = item.ID,
                   newRank = (item.UserRank + 1),
                    returnUrl = this.Request.RawUrl
               })

ex of controller

public ActionResult ChangeRank (int id, int newRank, string returnUrl)
        {            
            //DO something            
            return Redirect(returnUrl);
        }
dave317
  • 754
  • 2
  • 12
  • 30