samedi 21 janvier 2017

MVC Pass Selected Checkbox Items in Partial View to Controller

I have a partial view that I would like the client to make selections in using check-boxes. Then I want the Ids of the selected items sent to the controller when a submit button is clicked. The controller will redirect to a verification view. What would be a good,simple, and safe solution? I would like to avoid Javascript if possible. Thanks!

VIEW

@model OrderTracking.Models.ViewModel.ItemDataView

<div>

@using (Html.BeginForm("VerifyItem", "ReserveItem", FormMethod.Get))
{
    //@Html.AntiForgeryToken()  //TODO: Wire-up
    <table class="table table-striped table-condensed table-hover">
        <thead>
            <tr>
                <th></th>
                <th>Item ID</th>
            </tr>
        </thead>
        <tbody>

            @foreach (var i in Model.ItemProfile)
            {
                <tr>
                    <td>@Html.CheckBoxFor(r => i.IsSelected, new { @class = "checkbox" })</td>
                    <td>@Html.DisplayFor(r => i.ItemId)</td>

                </tr>
            }
        </tbody>
    </table>



    @Html.ActionLink("Verify Order Information", "VerifyOrderInfo", "ReserveItem", "", new { @class = "btn btn-primary btn-large" } ) 

}

MODEL

namespace OrderTracking.Models.ViewModel
{
public class ItemProfileView
{
    [Key]
    public int ItemId { get; set; }
    public bool IsSelected { get; set; }

}

public class ItemDataView
{
    public IEnumerable<ItemProfileView> ItemProfile { get; set; }
}

}

CONTROLLER

    public ActionResult VerifyOrderInfo()  
    {

        return View();

    }




Aucun commentaire:

Enregistrer un commentaire