This is a migrated thread and some comments may be shown as answers.

[Solved] How to set action parameters

1 Answer 156 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 1
John asked on 13 Mar 2012, 08:59 PM
I've been looking through the forum and can't find any decent examples of where people are passing in parameters to the MVC action that's being called in the .Action() code of the menu item.

Let's say I have an action in my Home controller called About, that has a parameter of 'defaultSearch'... I'm trying to figure out how to pass a value to that defaultSearch parameter.

Currently in my menu in my view i have the following:
item.Add().Text("View My Work List").Action("About", "Home");

In the controller I have the following: 
public ActionResult About(string defaultSearch = "")

What do I  need to add to pass data to the parameter?

1 Answer, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 15 Mar 2012, 08:23 PM
If anyone else hits this looking for an answer... 

item.Add().Text("Search Interactions").Action("About", "Home", new { defaultSearch = "myworklist" });

You don't have to worry about adding in the routes manually or anything. It just takes what you put in the object defined as new, and makes it the query string passed.

Just thought I'd provide this since I couldn't find it anywhere else. Hopefully someone else can benefit from my hours of messing with this until I found this out.
Tags
Menu
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Share this question
or