【问题标题】:Razor Page Call Modal From Code Behind on post asyncRazor Page Call Modal From Code Behind on post async
【发布时间】:2021-08-22 21:07:11
【问题描述】:

亲爱的,

我确实读取了条形码并在我阅读代码后通过回发将用户保存在数据库中,而在 OnPostAsync 中我验证了用户并且如果用户续订日期已过期,我想显示一个弹出窗口?那我该怎么做呢?

【问题讨论】:

    标签: asp.net-core .net-core razor-pages asp.net-core-razor-pages


    【解决方案1】:

    您可以使用ajax调用OnPostAsync然后在ajax成功时显示一个弹出窗口。这是一个演示:

    cshtml(可以把你要传递的数据放到ajax的data):

    @Html.AntiForgeryToken()
    <button onclick="postdata()">submit</button>
    @section Scripts
    {
        <script>
            function postdata() {
                $.ajax({
                    type: "POST",
                    url: '',
                    headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
                    data: { id: 1 }
                }).done(function (result) {
                    if (result.message != "") {
                        alert("message:"+result.message);
                        }
                        
                    });
                    
            }
        </script>
    
    }
    

    cshtml.cs:

    public async Task<IActionResult> OnPostAsync(int id)
            {
                //you can check if the user renewal date is expired here 
                if (id==1)
                {
                    return new JsonResult(new{ message = "user renewal date is expired" });
                }
                else {
                    return new JsonResult(new { message = "" });
                }
            }
    

    结果:

    【讨论】:

      猜你喜欢
      • 2018-01-19
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 2022-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      相关资源
      最近更新 更多