hi guys,, I'm learn how to use sweet alert in ASP.NET CORE MVC, data successfully saved in database but why the message information successfully saved not appear. Where it the mistake in this code. Any help could be appriciate.
this is the DokterController.cs
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using AdminLTEMvc.Models;
- using Microsoft.Extensions.Configuration;
- using System.Data;
- using Microsoft.Data.SqlClient;
- using Microsoft.Data;
- namespace AdminLTEMvc.Controllers
- {
- public class DokterController : Controller
- {
- private readonly IConfiguration _configuration;
- public DokterController(IConfiguration configuration)
- {
- this._configuration = configuration;
- }
- public IActionResult Index()
- {
- DataTable dt = new DataTable();
- using (SqlConnection con = new SqlConnection(_configuration.GetConnectionString("db_klinik")))
- {
- con.Open();
- SqlCommand cmd = new SqlCommand("Select * From Dokter", con);
- cmd.CommandType = CommandType.Text;
- SqlDataAdapter adap = new SqlDataAdapter(cmd);
- adap.Fill(dt);
- }
- return View(dt);
- }
- [HttpGet]
- public IActionResult TambahData()
- {
- ViewBag.pesan = TempData["pesan"] as string;
- return View();
- }
- public IActionResult TambahData(DokterModel dokterModel)
- {
- if (ModelState.IsValid)
- {
- using (SqlConnection con = new SqlConnection(_configuration.GetConnectionString("db_klinik")))
- {
- using (SqlCommand cmd = new SqlCommand("Insert Into Dokter (Nama_Dokter,Alamat,Jenis_Kelamin,Spesialisasi,Keahlian) Values ('" + dokterModel.Nama_Dokter + "','" + dokterModel.Alamat + "','" + dokterModel.Jenis_Kelamin + "','" + dokterModel.Spesialisasi + "','" + dokterModel.Keahlian + "')", con))
- {
- con.Open();
- cmd.Connection = con;
- cmd.CommandType = CommandType.Text;
- cmd.ExecuteNonQuery();
- TempData["pesan"] = "Data Berhasil disimpan...";
- return RedirectToAction("Index", "Dokter");
- }
- }
- }
- else
- {
- return View(dokterModel);
- }
- }
- }
- }
This is the TambahData.cshtml
- @addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
- @model AdminLTEMvc.Models.DokterModel
- @{
- Layout = "~/Views/Shared/AdminLayout.cshtml";
- }
- "viewport" content="width=device-width" />
-
Tambah Data Dokter - "~/dist/css/adminlte.min.css" rel="stylesheet" />
- "~/plugins/sweetalert2/sweetalert2.css" rel="stylesheet" />
-
class ="content"> - class="container-fluid">class="card card-green">class="card-header">
class
="card-title">Tambah Data Dokter- ="form-horizontal" asp-action="TambahData">
class="form-group row">- ="Nama_Dokter" class="col-sm-2 col-form-label">Nama Dokter
class="col-sm-10">- @*@Html.EditorFor(model => model.Nama_Dokter)
- @Html.ValidationMessageFor(model => model.Nama_Dokter)*@
- for="Nama_Dokter" id="Nama_Dokter" class="form-control" placeholder="Nama Dokter">
- for="Nama_Dokter" class="text-danger">
class="form-group row">- ="Alamat" class="col-sm-2 col-form-label">Alamat
class="col-sm-10">- ="Alamat" id="Alamat" class="form-control" rows="4" placeholder="Alamat">
- for="Alamat" class="text-danger">
class="form-group row">- ="Jenis_Kelamin" class="col-sm-2 col-form-label"> Jenis Kelamin
class="col-sm-10">- @Html.RadioButtonFor(model => model.Jenis_Kelamin, "Laki-Laki") Laki-Laki
- @Html.RadioButtonFor(model => model.Jenis_Kelamin, "Perempuan") Perempuan
- for="Jenis_Kelamin" id="Jenis_Kelamin" class="text-danger">
class="form-group row">- ="Spesialisasi" class="col-sm-2 col-form-label">Spesialisasi
class="col-sm-10">- for="Spesialisasi" id="Spesialisasi" class="form-control" placeholder="Spesialisasi">
- for="Spesialisasi" class="text-danger">
class="form-group row">- ="Keahlian" class="col-sm-2 col-form-label">Keahlian
class="col-sm-10">- ="Keahlian" id="Keahlian" class="form-control" rows="4" placeholder="Keahlian">
- for="Keahlian" class="text-danger">
class="form-group row">- ="col-sm-2 col-form-label">
class="col-sm-10">- class="btn btn-success"> Save Data
- "Index" class="btn btn-success">class="fa fa-arrow-back"> Back to List
this is the Index.cshtml
- @*
- For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
- *@
- @*@model AdminLTEMvc.Models.DokterModel*@
- @{
- Layout = "~/Views/Shared/AdminLayout.cshtml";
- }
- @model System.Data.DataTable
- "~/plugins/fontawesome-free/css/all.css" rel="stylesheet" />
class ="content">- class="container-fluid">
- "TambahData">class="fa fa-plus-square btn btn-success"> Tambah Data
class="table table-bordered table-responsive-lg table-hover" width="100%" id="myTable">
- class="thead-dark text-center">
- Nama Dokter
- Alamat
- Jenis Kelamin
- Spesialisasi
- Keahlian
- Action
- class="text-center">
- @for (int i = 0; i < Model.Rows.Count; i++)
- {
- @Model.Rows[i]["Nama_Dokter"]
- @Model.Rows[i]["Alamat"]
- @Model.Rows[i]["Jenis_Kelamin"]
- @Model.Rows[i]["Spesialisasi"]
- @Model.Rows[i]["Keahlian"]
- "UpdateData" asp-route-id="@Model.Rows[i]["Id_Dokter"]">class="fa fa-edit btn btn-sm btn btn-info"> Edit |
- "Delete" asp-route-id="@Model.Rows[i]["Id_Dokter"]">class="fa fa-trash btn btn-sm btn btn-danger"> Delete
- }
- "~/plugins/datatables/jquery.dataTables.min.css" rel="stylesheet" />

Jignesh KumarPosted Apr 10, 2021, 1:14 PM
Tri SetiaPosted Apr 10, 2021, 4:58 PM
Salman BegPosted Apr 10, 2021, 12:48 PM