Когда я сохраняю данные, они сохраняются со случайными идентификаторами 1015 и 1016.
Я выполнил все миграции и обновил базу данных, но она не отображает правильные данные в виде списка.
Служба получателя работает следующим образом:
public List<Receiver> GetReceivers()
{
return DbContext.Receivers.ToList();
}
public async Task CreateReceiver(ReceiverCreationModel model)
{
DbContext.Receivers.Add(Mapper.Map<ReceiverCreationModel, Receiver>(model));
await DbContext.SaveChangesAsync();
}
public Receiver ReceiverDetails(int id)
{
return DbContext.Receivers.SingleOrDefault(d => d.ReceiverId == id);
}
Контроллер приемника выглядит так:
public ActionResult Index()
{
return View(receiverService.GetReceivers());
}
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(ReceiverCreationModel model)
{
if (ModelState.IsValid)
{
await receiverService.CreateReceiver(model);
}
return RedirectToAction("Index");
}
Вид Create.cshtml
таков:
@model BBProjectnew.Models.Receivers.ReceiverCreationModel
@{
ViewBag.Title = "CreateReceivers";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>DonorCreationModels</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.ReceiverName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ReceiverName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ReceiverName, "", new { @class = "text-danger" })
</div>
@Html.LabelFor(model => model.ReceiverPhoneNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ReceiverPhoneNumber, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ReceiverPhoneNumber, "", new { @class = "text-danger" })
</div>
@Html.LabelFor(model => model.ReceiverAddress, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ReceiverAddress, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ReceiverAddress, "", new { @class = "text-danger" })
</div>
@Html.LabelFor(model => model.LastTimeReceived, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastTimeReceived, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LastTimeReceived, "", new { @class = "datepicker" })
</div>
@Html.LabelFor(model => model.BloodTypeReceived, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.BloodTypeReceived, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BloodTypeReceived, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
Я хочу, чтобы данные сохранялись в последовательности. Прямо сейчас он экономит с 1015 года.
введите описание изображения здесь