How to call javascript function in mvc4 controller?

Total Post:7

Points:49
 14917  View(s)
Ratings:
Rate this:

javascript code:

<script type="text/javascript">
function test(pa)
{
alert(pa);
}
</script>

index.cshtml

@using(Html.BeginForm("Index","Home"))

    {
    <button type="submit">Hello</button>
    }

Controller

public class HomeController : Controller, IJavaScriptModelAware
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            this.AddJavaScriptFunction("test", PageLoadEvent.Ready, null, "hello");
            return View();
        }

    }

I am fallow javascript model
install this
Install-Package JSM.MVC4
what is problem i can't understand please solve this problem

  1. Post:1

    Points:7
    Re: How to call javascript function in mvc4 controller?

    [HttpGet]
    public ActionResult SayHello()
    {
        var personSaluteU = SomeView.GetPerson();
        return Json(person, JsonRequestBehavior.AllowGet);
    }
    function GetPerson() {
     $(“#Button1″).click(function(otro){
                    alert(“Your name: ” + $(“#TextBox1″).val());
                });
    }
    maybe this help ful

      Modified On Apr-10-2018 01:06:05 AM
  1. Post:7

    Points:49
    Re: How to call javascript function in mvc4 controller?

    i am not want to return json return only view

    and waht is SomeView please discribe this

Answer