I am trying to send back the checkbox value back to the controller. The checkbox does not recognise the change in the checkboxfor and keep sending the values it got when I generated the page.

Could anyone explain where I have got it wrong? I have looked at few examples and unfortunately they do not fullfill my requirements.

My Class

public class SomeClass
    public Guid Id { get; set; }
    public string Name { get; set; }
    public bool IsEnabled { get; set; }

My Controller

    public ActionResult Index(Guid id,bool check = false)
            _importService.EnableDisable(id, check);
            return RedirectToAction("Index");
        catch (Exception ex)
            LogError(ex.Message, ex);

Razor Code

    <h4>Current Values</h4>
        @foreach (var m in Model)
                <td><a href="@Url.Action("ExtraInfo", "MyAction", new {id = m.Id})">@m.Name</a></td>
                    @using (Html.BeginForm("Index", "MyAction", new { id = m.Id, check = m.IsEnabled }, FormMethod.Post, null))
                        @Html.HiddenFor(m => SomeClass.Id)
                         @Html.CheckBoxFor(m => SomeClass.IsEnabled)

                        <input type="submit" value="Save" />

The Save button appears like this

Related posts

Recent Viewed