HI WELCOME TO KANSIRIS

How to call Javascript function in action?

Leave a Comment
In my view I has a function called testalert,and in my controller I has a action called Index,I use javascriptmodel can solve my problem,but I find that if my action do not return a view(),for example:just return Json(model),the javascriptmodel will not work.How to call js function when I return json?Why do the javascriptmodel only be designed to work well in return view?
    function testalert(para) {
         alert(para);
        }
 
    public ActionResult Index()
        {
      //work well  and alert "abc"
     this.AddJavaScriptFunction("testalert", PageLoadEvent.Ready, null, "abc");
            return View();
        }
    public ActionResult GetData()
        {
      var restult="data";
     // not work
     this.AddJavaScriptFunction("testalert", PageLoadEvent.Ready, null, "abc");
       return Json(restult);
        }

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.