views:

37

answers:

3

I don't know if this defeats the purpose of MVC, but I'd like to have a controller that accepts 2 variables but I don't what to pass them the url. Is there easy way to do that?

public ActionResult Return(string user_id, int item_id)

Right now I'm making links like this

<%: Html.ActionLink("Return", "Return", new {user_id = item.user_id, item_id = item.item_id}) %>

Is there an easy way that will post the data to a controller instead of passing data through the URL

+1  A: 

You have a couple options, but not with the ActionLink as that simply constructs a HTML a element.

You can use SESSION to pass data from controller to controller. Just ensure you are clearing those session variables after.

You can also just POST your data using a form.

It all depends on what your desired interface is, and when that data is available.

Dustin Laine
A: 

Use a form with hidden inputs:

<% using(Html.BeginForm()) { %>
    <%: Html.Hidden("user_id", item.user_id) %>
    <%: Html.Hidden("item_id", item.item_id) %>
    <button type="submit">Return</button>
<% } %>

If you don't like the button, you can style it with CSS to look like a link.

Dave
A: 

Using a HTTP POST, the values could be passed as key value pairs instead of in the URL, but in most cases where the operation is idempotent, you'd most likely want to use GET, in which case, there is no other way; the parameters are part of the URL either in the path or query string.

Russ Cam

related questions