zoukankan      html  css  js  c++  java
  • 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);
            }
        }
  • 相关阅读:
    django filefield
    django HttpResponseRedirect
    Django 自定义 error_messages={} 返回错误信息
    Django validators 官方文档
    djnago 官方关系反向查询案例
    django logging settings.py
    分页 restframe work 排序,分页,自定义过滤
    论文阅读笔记六十三:DeNet: Scalable Real-time Object Detection with Directed Sparse Sampling(CVPR2017)
    基于Distiller的模型压缩工具简介
    基于Intel OpenVINO的搭建及应用,包含分类,目标检测,及分割,超分辨
  • 原文地址:https://www.cnblogs.com/zjflove/p/12731885.html
Copyright © 2011-2022 走看看