我有更新模型的剃刀视图。模型正确地传递给视图,但是当尝试将提交更改回控制器时,模型将不加改变地传回。
//控制器/ SaveLimit
public ActionResult SaveLimit(Limit _limit)
{
_masterData.SaveLimit(_limit);
return RedirectToAction("MasterData");
}
//视图
@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>
答案 0 :(得分:1)
看起来它不起作用的原因是因为你没有提交按钮。普通链接不会提交表单(除非您添加一些JavaScript)。将其添加到您的视图中:
@using (Html.BeginForm("SaveLimit", "yourcontroller"))
{
// Rest of view
<input type="submit" value="Save" />
}
答案 1 :(得分:0)
答案 2 :(得分:0)
看起来你错过了表格。把你的表格包裹在里面:
using (@Html.BeginForm())
{
...
}