-
-
Save tklives/5723855 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web.Mvc; | |
namespace AjaxTest.Controllers | |
{ | |
public class HomeController : Controller | |
{ | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public JsonResult TestPost(PostData postedData) | |
{ | |
var obj = new DummyData {Here = "Is me", What = "Is that", Echo = postedData.PostedGuid}; | |
return Json(obj); | |
} | |
} | |
public class PostData | |
{ | |
public Guid? PostedGuid { get; set; } | |
} | |
public class DummyData | |
{ | |
public string What { get; set; } | |
public string Here { get; set; } | |
public Guid? Echo { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>@ViewBag.Title - My ASP.NET MVC Application</title> | |
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> | |
<meta name="viewport" content="width=device-width" /> | |
<script src="~/Scripts/jquery-1.8.2.js"></script> | |
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> | |
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script> | |
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script> | |
</head> | |
<body> | |
<div id="body"> | |
<section> | |
@RenderBody() | |
</section> | |
</div> | |
</body> | |
<script type="text/javascript"> | |
function CallMe(input) { | |
alert(input); | |
} | |
</script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model AjaxTest.Controllers.PostData | |
@{ | |
ViewBag.Title = "Home Page"; | |
} | |
<div id="result"></div> | |
@using (Ajax.BeginForm("TestPost", "Home", new AjaxOptions { OnComplete = "CallMe" })) | |
{ | |
@Html.EditorFor(x => x.PostedGuid) | |
@Html.ValidationMessageFor(x => x.PostedGuid) | |
<input type="submit" value="OK" /> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment