У меня проблема с моим методом редактирования в моем контроллере.Параметр ответа всегда остается нулевым при отправке формы редактирования.
Что я могу сделать, чтобы SmallTalkAnswer в методе редактирования записал его обратно в базу данных?
Контроллер содержит метод редактированиякак указано в документации MS:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(SmallTalkAnswer answer)
{
var a = ModelState.IsValid;
_smallTalkAnswerRepository.Update(answer);
return RedirectToAction("Index");
}
Представление генерируется Visual Studio:
@model ChatBotAdminCenter.Models.SmallTalkAnswer
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>SmallTalkAnswer</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.PartitionKey, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PartitionKey, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PartitionKey, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.RowKey, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.RowKey, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.RowKey, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Timestamp, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Timestamp, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Timestamp, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ETag, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ETag, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ETag, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Answer, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Answer, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Answer, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
Модель:
public class SmallTalkAnswer : TableEntity
{
public SmallTalkAnswer() { }
public SmallTalkAnswer(string hash, string categoryId)
{
this.PartitionKey = hash;
this.RowKey = categoryId;
}
public string Hash => PartitionKey;
public string CategoryId => RowKey;
public string Answer { get; set; }
}