2
かかります。 しかし、テーブルの主キーは常にシーケンス内にあります。MVC5主キーは常に私は私のモデルに新しい行を作成しようとしていますここでmvc5アプリケーションを持っているシーケンス
しかし、私はビューに与えるキーが主キーとして使用することにしたいです。 私はMVCを初めて使い、ここで間違っていることがわかりません。
これは私のコントローラ
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ProviderId,ProviderName")] Provider provider)
{
if (ModelState.IsValid)
{
db.Providers.Add(provider);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(provider);
}
である私は、プロバイダにその値をデバッグ中にする観点から、どのようなI入力であることがわかります。私は私が私のテーブルにProviderIdとして保存することが私の見解で入力したものは何でもしたい
public class Provider
{
[Key]
public int ProviderId { get; set; }
public string ProviderName { get; set; }
}
public class ProviderDBContext : DbContext
{
public DbSet<Provider> Providers { get; set; }
}
:
<div class="form-group">
@Html.LabelFor(model => model.ProviderId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProviderId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProviderId, "", new { @class = "text-danger" })
</div>
@Html.LabelFor(model => model.ProviderName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProviderName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProviderName, "", new { @class = "text-danger" })
</div>
</div>
はここに私のモデルクラスです:
は、ここに私のビューの私の一部です。
助けてください。
チャームのように働いた!ありがとうございました – sunny