Skip to content

Instantly share code, notes, and snippets.

@rionmonster
Created April 21, 2016 17:33
Show Gist options
  • Save rionmonster/2a62521a07335bb56d20dc897ef0ba94 to your computer and use it in GitHub Desktop.
Save rionmonster/2a62521a07335bb56d20dc897ef0ba94 to your computer and use it in GitHub Desktop.
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string posted)
{
return Content(posted + " was posted.");
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Post Testing</title>
</head>
<body>
<h2>Normal Form</h2>
@using (Html.BeginForm("Index", "Home"))
{
<input type="hidden" name="posted" id="posted" value="5" />
<input type="submit" id="sBtn" value="Submit" />
}
<h2>AJAX Form</h2>
@using (Ajax.BeginForm("Index", "Home", new AjaxOptions() { HttpMethod = "Post", UpdateTargetId = "DivName" }))
{
<input type="hidden" name="posted" id="posted" value="5" />
<input type='submit'>
}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment