0

Using asp.net MVC 3, I would like to add a query string on every request of Controller's method, using the following code, the query string is not being added to the URL.

Any idea what I am doing wrong or any other alternative approaches?

  public ActionResult Index(string uniquestudentreference)
    {
        return View(eventListVM);
    }

 public class UserAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.ActionParameters["uniquestudentreference"] = Various.GetGivenNameUser();
        }
    }

2 Answers 2

1

If you want the uniquestudentreference parameter to have a value in your controller action, you should simply invoke the controller action with the correct url like:

http://www.someurl.com/<controller>/Index/<uniquestudentreference>

If you want to affect how you pass information through the url, you should look into customizing your route table (located in Global.asax)

You can read more about that here: http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs

Sign up to request clarification or add additional context in comments.

2 Comments

What I need is to append a Query String not adding a slug to the URL. This should work as soon as the page load.
Then i guess you could override the Initialize method of your controller, and add the value (msdn.microsoft.com/en-us/library/…)
0

What you want to do here is set the value to the ViewData or TempData of the ControllerContext in the ActionResult, and then reference it in the method. This is a better way to pass it around than querystring, and safer too (avoids user being able to manipulate the value). That or store the value in the Session.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.