Я довольно новичок в MVC, и мой английский очень плохой.Теперь я застрял с параметром всегда равным нулю в моем параметре ActionResult.
Вот контроллер
[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
всегда равно нулю, когда я его отлаживаю.Кто-то видит, где проблема?Должен ли я добавить больше деталей?
Спасибо!