0

I've searched and found several questions similar to mine, but the answers are too specific to the OP's situation to help.

On my Main view, I have a table of items and action links for each of those items:

Item Name   Actions
Item #1     Foo | Bar
Item #2     Foo | Bar

The Main view displays this table with the following 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 you can see, each item in the Main view's table links to the Test controller/view.

The Test controller's Index action is defined as:

    public ActionResult Index(Item item)
    {
        return View(item);
    }

The Test view is then defined to accept the Item model:

@model Models.Item

This all works and the Test view displays the Item object's data.

However, I now need Foo and Bar to display the Test controller/view in two distinct ways, or modes.

Something like:

?mode=foo&item=Item
?mode=bar&item=Item

How do I pass both the Item object and a mode to my Test controller so that the Test view will behave appropriately based on the mode?

1 Answer 1

1

Add the mode to the route values. You'll have to expand Item's properties

@Html.ActionLink("Foor", "Index", "Test", new { mode = "foo", propA = item.PropA }, null)
Sign up to request clarification or add additional context in comments.

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.