• RazorPage-Get、Post、自定义handler、ajax、partial


    OnGet/Post{Handler}{Async}

    @page
    @model CoreMvc.PM1Model
    @{
        ViewData["Title"] = "PM1";
    }
    
    <h1>PM1</h1>
    
    <p>
        nj:   @Model.Age+@Model.name
    </p>
    <form>
        @Html.AntiForgeryToken()
        <p>
            name:<input asp-for="name" />
            <input type="submit" value="sumbit"  formmethod="post" />
        </p>
        <p>
            <button asp-page-handler="Demo1" formmethod="post">自定义Handler</button>
        </p>
        <p>
            <button onclick="ajax(); return false;">ajax</button>
        </p>
        <p>
            @await Html.PartialAsync("_CustomPartial", new PartialCus { Name = Model.name, Age = Model.Age, CurrTime = DateTime.Now })
        </p>
    
        <partial name="_CustomPartial" model="new PartialCus { Name = Model.name, Age = Model.Age, CurrTime = DateTime.Now }" />
    
        @{
            var partiCUs = new PartialCus { Name = Model.name, Age = Model.Age, CurrTime = DateTime.Now };
        }
        <partial name="_CustomPartial" for="@partiCUs" />
    </form>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script type="text/javascript">
        function ajax() {
            alert(3232);
            $.ajax({
                //请求方式
                type: "POST",
                //请求的媒体类型
                //contentType: "application/json;charset=UTF-8",
                //请求地址
                url: "?handler=ajax1",
                headers: {
                    //.AddRazorPagesOptions(o=> o.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute()));
                    RequestVerificationToken:
                        $('input:hidden[name="__RequestVerificationToken"]').val()
                },
                dataType: "JSON",
                //数据,json字符串
                data: { name: "ajax-name", age: 10 },
                //请求成功
                success: function (result) {
                    alert(result)
                },
                //请求失败,包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });
        }
    </script>
    public class Person1
        {
            public int Age { get; set; }
            public string Name { get; set; }
            protected string Name2 { get; set; }
        }
        [BindProperties(SupportsGet =true)]
        public class PM1Model : PageModel
        {
             
            public int Age { get; set; }
            public Person1 Person { get; set; }
            //[FromForm]
            public string name { get; set; } 
            public void OnGet()
            {
    
            }
    
            public void OnPost()
            {
    
            }
            public void OnPostDemo1()
            {
    
            }
            public JsonResult OnPostAjax1()
            { 
                return new JsonResult(Person);
            }
        }
  • 相关阅读:
    推荐系统相关知识
    关于hive核心
    关于hive的基础
    立个flag
    关于数据增强——文本增强
    .NET Core 实践:事件通知和异步处理
    .NET Core 实践:微服务架构的优点
    C#一定比C++性能差?当然不!破除迷信,从我做起!
    Visual Studio Code 搭配 Docker 一键搭建golang开发环境
    单例双重检查引发的资源竞争/数据竞争
  • 原文地址:https://www.cnblogs.com/zjflove/p/12731885.html
Copyright © 2020-2023  润新知