asp.net mvc - Passing multiple parameters to an MVC controller -
i've searched , found several questions similar mine, answers specific op's situation help.
on main view, have table of items , action links each of items:
item name actions item #1 foo | bar item #2 foo | bar
the main view displays table next code:
@foreach (var item in model) { <tr> <td>@html.displayfor(modelitem => item.title)</td> <td> @html.actionlink("foo", "index", "test", item, null) | @html.actionlink("bar", "index", "test", item , null) </td> </tr> }
as can see, each item in main view's table links test controller/view.
the test controller's index action defined as:
public actionresult index(item item) { homecoming view(item); }
the test view defined take item model:
@model models.item
this works , test view displays item object's data.
however, need foo , bar display test controller/view in 2 distinct ways, or modes.
something like:
?mode=foo&item=item ?mode=bar&item=item
how pass both item object , mode test controller test view behave appropriately based on mode?
add mode route values. you'll have expand item
's properties
@html.actionlink("foor", "index", "test", new { mode = "foo", propa = item.propa }, null)
asp.net-mvc asp.net-mvc-4
No comments:
Post a Comment