Reputation: 26071
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
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
Reputation: 15513
Looks like you're missing the form. Wrap your form inside this:
using (@Html.BeginForm())
{
...
}
Upvotes: 0