0

Here is the hyperlinked code I am generating to show a list of merchants:

    <td>

        @Html.ActionLink(Html.DisplayFor(modelItem => item.MerchantName).ToHtmlString(), "ViewMerchant", "Merchants")
    </td>

What I would like for it to do is to take me to a new page where it shows just the information on the merchant selected (address, webaddress, etc), so a ViewMerchant page in my Merchants View folder.

Can I grab the MerchantID in this ActionLink? If so how would that code look in the above ActionLink?

Secondly in the View Merchants page if anyone could link me to a site that would explain how to build that so the page gets populated with the merchant info would be ideal.

zed
  • 2,298
  • 4
  • 27
  • 44
JP Hochbaum
  • 637
  • 4
  • 15
  • 28
  • [link](http://stackoverflow.com/questions/5593759/actionlink-with-multiple-parameters) Shows how to pass parameters to your ActionLink. – tcrite Aug 06 '15 at 18:59
  • Ok that got me looking in the right direction, so I found this: new { id=item.MerchantId }, as a sample parameter that would seem to work. What I see as the problem is that I will have a array of menu items attached to the merchant, so wondering if that Menu will also display (which is what I am aiming to do ultimately). – JP Hochbaum Aug 06 '15 at 19:06
  • Not sure I understand what you are saying in your comment, please edit and update your question with more detail. – zed Aug 06 '15 at 19:08

1 Answers1

3

You can pass the MerchantID as a route value as follows:

@Html.ActionLink("Link text", "ViewMerchant", "Merchants", new { id = item.MerchantID }, null )

Where ViewMerchant is the name of your action instide MerchantsController

And here is a small sample to your details action:

public ActionResult Details(int id)
{
    Merchant merchant = db.Merchants.Find(id);

    return View(merchant);
}

Of course, you should use ViewModels instead of passing your model to the view. But that's another matter on which you can find many information online. Here is one link to start reading about it.

Community
  • 1
  • 1
zed
  • 2,298
  • 4
  • 27
  • 44