Many Buttons on a Page, Need to send back Unique Post Data with each

Posted by CoffeeAddict on Stack Overflow See other posts from Stack Overflow or by CoffeeAddict
Published on 2012-03-29T21:37:57Z Indexed on 2012/03/30 5:30 UTC
Read the original article Hit count: 130

Filed under:

I'm listing out a bunch of cars with a button next to them that when clicked will need to perform a GET but also sends over that item's model.Name:

@using (Html.BeginForm("GetCarUrl", "Car", FormMethod.Get, new { model = Model }))
{
    if(Model.Cars != null && Model.Cars.Count > 0)
    {       
        foreach (CarContent car in Model.Cars)
        {
            <p>@car.Name</p>
        }

            <input type="button" value="Get Car Url" class="submit" />
    }

So the page renders a bunch of hyperlinks and buttons:

[hyperlink1] [submit]
[hyperlink2] [submit]
[hyperlink3] [submit]
[hyperlink4] [submit]
[hyperlink5] [submit]
...

When a user clicks on any of the submits, I need to pass back its corresponding @car.CarType for that specific hyperlink

Not sure how to go about this. My action method expects a @car.CarType for that specific car hyperlink to be sent to it

© Stack Overflow or respective owner

Related posts about asp.net-mvc-3