削除ボタンを押してもインデックスページのテーブルから行を削除するにはどうしたらいいですか?データベース。 私は、Visual Studio 2017とSQL Server 2016データベースから削除せずに削除ボタンを押すと、インデックスページのテーブルから行を削除するには
// GET: Information/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Information information = db.Informations.Find(id);
if (information == null)
{
return HttpNotFound();
}
return View(information);
}
// POST: Information/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
Information information = db.Informations.Find(id);
db.Informations.Remove(information);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
このコードは、データベースから選択された行を削除するとasp.netのmvc5を使用しています。私はインデックスページから削除したいです。 誰も私に何かヒントを与えることができます。
ありがとうございました!しかし、どこでこれを書くことができますか?多分ここに?パブリックActionResult DeleteConfirmed(int id) { 情報情報= db.Informations.Find(id); db.Informations.Remove(information); db.SaveChanges(); リターンRedirectToAction( "Index"); 私はちょうど初心者です! – Hamiprogrammer
いいえ、私が書いたコードはJavaScriptであり、コントローラはC#です。 –
どうすればC#で記述できますか?どこに書きますか? – Hamiprogrammer