码迷,mamicode.com
首页 > Web开发 > 详细

AjaxHelper学习,ajax,microsoft,mvc,asp.net

时间:2014-08-13 22:20:47      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   ar   art   

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; }
    }

AjaxHelper学习,ajax,microsoft,mvc,asp.net,布布扣,bubuko.com

AjaxHelper学习,ajax,microsoft,mvc,asp.net

标签:style   blog   color   os   io   for   ar   art   

原文地址:http://www.cnblogs.com/bushuosx/p/3911165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!