Wednesday 11 October 2017

Multiple Action methods in Same Page (Razor View) in ASP.Net MVC

Multiple Action methods in Same Page (Razor View) in ASP.Net MVC

Description:

In this example we explain that how to call multiple Action methods in same page in Asp.Net MVC.or how to implement multiple Action Methods in same page in MVC.or how to use multiple action method in same controller in MVC Razor. Multiple Action methods in same razor view in MVC.or how to use multiple Action Methods of same controller in same Razor view in MVC.
Controller:

  public class EmployeeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Save()
        {
            TempData["Message"] = "You clicked on Save Button!";
            return RedirectToAction("Index");
        }

        [HttpPost]
        public ActionResult Cancel()
        {
            TempData["Message"] = "You clicked on Cancel Button!";
            return RedirectToAction("Index");
        }
    }

View: 

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Multiple Action methods in Same Page (View) in ASP.Net MVC</title>
</head>
<body>
    <table>
        <tr>
            <td>
                @using (Html.BeginForm("Save", "Employee", FormMethod.Post))
                {
                    <input type="submit" id="btnSave" value="Save"/>
                }
            </td>
            <td>
                @using (Html.BeginForm("Cancel", "Employee", FormMethod.Post))
                {
                    <input type="submit" id="btnCancel" value="Cancel"/>
                }
            </td>
        </tr>
    </table>
 
    @if (TempData["Message"] != null)
    {
       <script type="text/javascript">
           window.onload = function () {
               alert('@TempData["Message"]');
           };
        </script>
    }
</body>
</html>



This entry was posted in :

0 comments:

Post a Comment