我是MVC的新手,我的英语很差。现在,我在ActionResult参数中始终将参数设置为null。
这是控制者
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "TimeCodeId, Code, Title, Description, IsValid, DateCreated")] TimeCodeInfo infoTimeCode, string submitButton)
{
bool result;
switch (submitButton)
{
case "Update":
case "Enregistrer":
infoTimeCode.LastDateModified = DateTime.Now;
result = _mTimeCode.Update(infoTimeCode);
return RedirectToAction("List");
case "Cancel":
case "Annuler":
return RedirectToAction("List");
//break;
}
return View(infoTimeCode);
}
这是cshtml
@using (Html.BeginForm("Edit", "TimeCode", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.HiddenFor(Model => Model.TimeCodeId)
<table class="w3-table w3-card">
<tr>
<td>Code:</td>
<td>
@Html.EditorFor(model => model.Code)
@Html.ValidationMessageFor(model => model.Code)
</td>
</tr>
<tr>
<td>Titre:</td>
<td>
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</td>
</tr>
<tr>
<td>Description:</td>
<td>
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</td>
</tr>
<tr>
<td>Est valide ?</td>
<td>
@Html.EditorFor(model => model.IsValid)
@Html.ValidationMessageFor(model => model.IsValid)
<label class="switch" onsubmit="@Model.IsValid = getCheckBoxValue('switchCheckBox')">
<input id="switchCheckBox" type="checkbox" name="IsValid">
<span class="slider round"></span>
</label>
</td>
</tr>
<tr>
<td>Date de création:</td>
<td>@Model.DateCreated</td>
</tr>
<tr>
<td>Dernière modification:</td>
<td>@Model.LastDateModified</td>
</tr>
</table>
<br />
<a href="/TimeCode/List" class="w3-round-medium w3-button w3-blue"><i class="fa fa-caret-left"></i> Retour à la liste</a>
<div class="float-right">
<button type="submit" value="enregistrer"> enregistrer </button>
@*<a type="submit" href="~/Views/TimeCode/List.cshtml" class="w3-right w3-round-medium button buttonBlue">Enregistrer</a>*@
<a href="/TimeCode/List" class="w3-right w3-round-medium button buttonBlue">Annuler</a>
</div>
}
调试时,参数submitButton
始终为null。有人看到问题出在哪里吗?我需要添加更多详细信息吗?
谢谢!