首页 > 解决方案 > 如何在 Form Post 返回 RedirectToAction 之前使用 SweetAlert?

问题描述

模型

public class Company{
    [StringLength(30)]  
    public string Name{ get; set; }

    [StringLength(15)]
    public string RegisterNo { get; set; }
}

看法

<form id="form" method="post" action="/Controller/Save" style="font-size:13px;">
  <div class="row pb-3">
    <div class="form-row">
      <div class="col-md-3">
        <div class="position-relative form-group">
          <label class="">Company Name</label> @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control", @maxlength = "30" } })
        </div>
      </div>
    </div>
    <div class="form-row">
      <div class="col-md-6">
        <div class="position-relative form-group">
          <label class="">Reg No</label> @Html.EditorFor(model => model.RegisterNo, new { htmlAttributes = new { @class = "form-control", @maxlength = "15" } })
        </div>
      </div>
    </div>
  </div>
</form>
<button name="submit">Save</button>

控制器

public ActionResult Save(Company CompDet){
     string Name = CompDet.Name;
     string RegNo = CompDet.RegisterNo;

     //then Connect DB and Save DB
     //HOW TO use SweetAlert before, return RedirectToAction
}

我目前正在使用,return RedirectToAction仅。

如何在 RedirectToAction 之前添加 SweetAlert?

使用 Ajax Post 还是 Form Post?

可以同时使用 Ajax 和 Form Post 吗?

保存后 -> 显示 Sweetalert 成功 -> 返回 redirectToAction

我还处于学习阶段。请帮忙。

谢谢你

标签: asp.net-mvcsweetalert

解决方案


推荐阅读