首页 > 代码库 > AjaxHelper学习,ajax,microsoft,mvc,asp.net
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; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。