zoukankan      html  css  js  c++  java
  • AjaxHelper学习,ajax,microsoft,mvc,asp.net

    index.cshtml

    @using (Ajax.BeginForm("ContentAjax", new AjaxOptions { UpdateTargetId = "pajax" }))
    {
        <div>
            <p id="pajax"></p>
            <input class="text" name="username" />
            <button class="btn-default">ContentAjax测试</button>
        </div>
    }
    
    <div>
        @Ajax.ActionLink("JsonAjax测试", "JsonAjax", new AjaxOptions { OnSuccess = "jsonshow" })
    </div>
    
    <script>
        function jsonshow(data)
        {
            $("#pajax").html("用户ID:" + data.id + "<br/>"
                + "姓名:" + data.name + "<br/>"
                + "Email:" + data.email);
        }
    </script>
    
    <div>
        @Ajax.ActionLink("PartialViewAjax测试", "PartialViewAjax", new AjaxOptions { UpdateTargetId = "pajax" })
    </div>
    
    @section Scripts{
        @Scripts.Render("~/bundles/jqueryval")
    }

    HomeController.cs

    public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult ContentAjax(string username)
            {
                return Content("Content:" + "<br>" + "用户名:" + username);
            }
    
            public ActionResult JsonAjax()
            {
                UserInfo user = new UserInfo { id = 1, name = "Json", email = "json@qq.com" };
                return Json(user, JsonRequestBehavior.AllowGet);
            }
    
            public ActionResult PartialViewAjax()
            {
                UserInfo user = new UserInfo { id = 2, name = "PartialView", email = "PartialViewAjax@qq.com" };
                return PartialView("PartialViewAjax",user);
            }

    PartialViewAjax.cshtml

    @model MvcBasic.Models.UserInfo
    <p>
        用户ID:@Model.id
        <br/>
        姓名:@Model.name
        <br/>
        Email:@Model.email
    </p>

    Model

    public class UserInfo
        {
            public int id { get; set; }
    
            public string name { get; set; }
    
            public string email { get; set; }
        }
  • 相关阅读:
    java中调用kettle转换文件
    开源游戏引擎体验
    cocos2d-x 托付模式的巧妙运用——附源代码(二)
    BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 Windows Phone
    redis String结构
    Redis 键命令
    Redis 基础命令
    linux curl 命令的使用
    将spring boot项目部署到tomcat容器中
    Redis常用命令
  • 原文地址:https://www.cnblogs.com/bushuosx/p/3911165.html
Copyright © 2011-2022 走看看