0
votes

I have a view that the model is IEnumerable. the view is the mvc basic view that is created upon creating new controller with read write actions. I do not want that the edit action will call a different view, i want to add a button in the index view that by pressing the button in a specific row the button will call the action result with the model that was "pressed" and from there the logic will continue.

The View

@model IEnumerable<V1_ILotto.Areas.Admin.Models.WithdrawalModel>

@{
    ViewBag.Title = "בקשות משיכה";
}

<h2>בקשות משיכה</h2>

@using (Html.BeginForm("Approve", "Withdrawals", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <table>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.User)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.WithdrawalAmount)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Balance)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.IsApproved)
            </th>
            <th></th>
        </tr>

        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.User)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.WithdrawalAmount)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Balance)
                </td>

                <td>
                    <p>
                        <input type="submit" value="Submit" />
                    </p>
                </td>

            </tr>
        }
    </table>
}

The Controller

[HttpPost]
        public ActionResult Approve(WithdrawalModel withdrawalmodel)
        {
            if (ModelState.IsValid)
            {
                //logic for updating the db
                return RedirectToAction("Index");
            }
            return View(withdrawalmodel);
        }

Note : the view is in not getting a single model but IEnumerable of that model

1

1 Answers

1
votes

only for helpers (except display) tie the data to the model. If you want data passed back you need to put your values in at least a hidden for

@Html.HiddenFor(x => x.Balance) 

etc