Tuesday 29 March 2016

MVC - ActionLink with PostBack

Watch this example on YouTube
1. Add the following to _Layout file
        @Scripts.Render("~/Scripts/jquery-1.8.2.min.js")
        @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.js")
    </head>

2. create Action Link in View:
@Ajax.ActionLink("RecordID", "Index", new AjaxOptions { HttpMethod = "POST"})

3. create new method in Controller that will respond to postback
        [HttpPost]
        public ActionResult Index(Customer model)
        {
            return View(db.Customers.ToList());
        }

No comments:

Post a Comment