Antarr Byrd
Antarr Byrd

Reputation: 26071

Values not being updated in view

I have a razor view for updating a model. The model is passed the the view correctly but when try the submit changes back to the controller the model is passed back unchanged.

//controller/SaveLimit

  public ActionResult SaveLimit(Limit _limit)
        {
            _masterData.SaveLimit(_limit);

            return RedirectToAction("MasterData");
        }

//view

@model Core.DataModel.Limit
@{
    ViewBag.Title = "Calculation Master";
    Layout = "~/Views/Shared/_MasterLayout.cshtml";
}

<h2 class="centerText">Create New Employee Limit</h2>
    <div id="tabs" style="margin-left: 20px; padding-left: 20px; width: 90%;">

        <table style="margin-left: 50px; width: 35%; margin: 0 auto;">
            @using (Html.BeginForm())
            {
                <tr>
                    <td class="spin">
                        @Html.LabelFor(model => model.Limit)

                    </td>
                    <td>
                        @Html.EditorFor(model => model.Limit)

                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.LabelFor(model => model.StartDate)
                    </td>
                    <td>
                        @Html.EditorFor(model => model.StartDate)
                    </td>

                </tr>
                <tr>
                    <td>@Html.ActionLink("Save", "SaveLimit", Model, new {@class = "button"})</td>
                    <td>@Html.ActionLink("Cancel", "MasterData", null, new {@class = "button"})</td>
                </tr>
            }
        </table>

    </div>

Upvotes: 0

Views: 49

Answers (3)

John H
John H

Reputation: 14655

Looks like the reason it's not working is because you don't have a submit button. A normal link won't submit the form (unless you add some JavaScript). Add this to your view:

@using (Html.BeginForm("SaveLimit", "yourcontroller"))
{
    // Rest of view
    <input type="submit" value="Save" />
}

Upvotes: 1

Jerad Rose
Jerad Rose

Reputation: 15513

Looks like you're missing the form. Wrap your form inside this:

using (@Html.BeginForm())
{
    ...
}

Upvotes: 0

Val
Val

Reputation: 539

I guess you need to wrap all these in Form or BeginForm. Or show your background javascript if you have some.

Upvotes: 0

Related Questions