Thursday, 18 May 2017

call javascript function from Controller in MVC 4

How to call the javascript function in mvc Action Result
Description:
In this example we explain that how to call the JavaScript function in MVC Action Result method.or how to call JavaScript method from controller in MVC. or how to call JavaScript function in MVC 4 controller.there are many question are raised in our mind to call the JavaScript function from back-end in MVC or call JavaScript function from controller’s ActionReasult method.
View:

<script type=”javascript”>
@ViewBag.calljavascriptfunction

function Javascriptfunction()
{
  alert(“function is called from the controller”);
}
</script>

Controller:

public ActionResult Index()
{
 ViewBag.calljavascriptfunction = "Javascriptfunction();";
   return View();
}


0 comments:

Post a Comment