0

I have a view like this:

@model SCWW.Areas.OnlineBookings.Models.Updates.UpdateDetailsModel

@using (Html.BeginForm("Apply", "Updates", new { area = "OnlineBookings", consignmentKey = Model.ConsignmentKey }, FormMethod.Post, new { id = "updateableForm" }))
{
<fieldset>
    <legend>Updateable - @Html.DisplayFor(model => model.ConsignmentKey)</legend>
    <div class="well well-small ">
        @Html.HiddenFor(m => m.ConsignmentKey)

        <table id="updateDetails" class="table table-bordered table-striped table-hover dataTable">
            <tbody>
                <tr>
                    <td>Completed Date</td>
                    <td>@Html.CheckBoxFor(m => m.Apply)</td>
                    <td class="table-input">@Html.TextBoxFor(m => m.CompletedDate, new { Disabled = "Disabled" })</td>
                </tr>
                <tr>
                    <td>Cancelled Date</td>
                    <td>@Html.CheckBoxFor(m => m.Apply)</td>
                    <td class="table-input">@Html.TextBoxFor(m => m.CancelDate, new { Disabled = "Disabled" })</td>
                </tr>
                <tr>
                    <td>Booking Number</td>
                    <td>@Html.CheckBoxFor(m => m.Apply)</td>
                    <td class="table-input">@Html.TextBoxFor(m => m.BookingNumber, new { Disabled = "Disabled" })</td>
                </tr>

            </tbody>
        </table>
        <button type="submit" id="applyProxy" name="action" value="@FormAction.Apply" class="btn btn-success">Update</button>
    </div>

</fieldset>

}

Controller:

 [HttpPost]
    public ActionResult Apply(UpdateDetailsModel model, FormAction action)
    {
        if (!ModelState.IsValid)
        {
            return View("Submit",     GenerateViewModel(model.ConsignmentKey));
        }

        updateableService.Update(model.ConsignmentKey,"CompletedDate", model.ToDto());

        return RedirectToActionWithHash("Details", "otherActionsTab", "Bookings",
                                       new { consignmentKey = model.ConsignmentKey });
    }

In my view there 3 rows each with one checkbox. Only one checkbox is seleted when i click "update" button on View. How would i get to know which checkbox is selected? How to pass the selected checkbox value from view to controller - Apply(UpdateDetailsModel model, FormAction action) in controller

1 Answer 1

1

You're using the same model property 3 times. You'll need to create separate properties for each condition.

Sign up to request clarification or add additional context in comments.

2 Comments

is there an other way instead of using 3 separate properties? Please.
Nothing that is not ambiguous. You could guess based on which textbox has input in it, but that breaks as soon as the user puts input in > 1 textbox even if they only select one option. You need 3 properties for 3 choices.

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.