tags:

views:

50

answers:

3

Hi friends, I'm trying to send the user id (integer) from a view to the action. If I pass it using routevalues object, the user id will be visible in the browser address bar. How can I pass user id from view to the action without using aforementioned method??

+1  A: 

The user id is commonly inferred from your authentication mechanism (cookie etc), so for the current user you shouldn't need to pass it around.

The main time you would include this in the request is when the page being displayed relates to users - and in particular where you (or an admin) want to browse other users records - then you might use "/users/current/orders" (use the cookie) or "/users/12345/orders" (and you should verify permission to browse 12345).

Note that if you use /current/ or similar, you should ensure it isn't cached between different users - so in many ways it is simpler to just show the user-id and to heck with the url; just go for the simple "/users/12345/orders" case.

What is the scenario here?

Marc Gravell
There is a list of friends on the page and after clicking "Remove" link, that userid(friend id) should be passed to the action.I tried viewdata but since i'm using foreach() loop, I'm getting the error as "Item with that name is already added to viewdata".
buntykawale
A: 

There is a list of friends on the page and after clicking "Remove" link, that userid(friend id) should be passed to the action. I tried viewdata but since i'm using foreach() loop, I'm getting the error as "Item with that name is already added to viewdata".

buntykawale
+1  A: 

You can use a hidden input element inside a form. You should generally use POST, not GET (i.e. use a form, not an a href) for anything that is changing data in your system.

Steve Willcock
+1; but it is just so darned **funny** when google deletes all your data when crawling the links on your site ;-p
Marc Gravell
Hehe, absolutely :)
Steve Willcock