calling a jquery function from asp.net mvc action


calling a jquery function from asp.net mvc action



After posting a form to database is it possible to call a jquery from asp.net mvc.....

 [AcceptVerbs(HttpVerbs.Post)]         public ActionResult Create(FormCollection collection)         {             try             {                 //Insert to db                 //Call a jquery function                  return RedirectToAction("Index");             }             catch             {                 return View();             }         } 

should i use ScriptManager.RegisterClientScriptBlock after the insert or any other way to do this... Any suggestion...


how can i keep my url when my validation fail in asp.net mvc controller action

1:

ASP.NET MVC NerdDinner Tutorial question
No. Can submit buttons in Ajax forms have their name attribute set?You cannot call a jQuery function from an action. Difference between window.location.href and top.location.hrefThe way to did this in MVC is to simply add the function in the View's .aspx page and just wrap it in the $(document).ready(function(){}) (or w/e the function is for your library) so this when the page fully loads, the function will be called.. unable to download dynamically created file It is important to note this with MVC you have complete control of the HTML (JavaScript included) output and you should utilize that. Late binding operations cannot be converted to an expression tree with LINQWhile in WebForms its best to avoid using inline tags <% %>, in MVC, you're expected to use them to generate the HTML you want.. Returning JSON data to view page in ASP.NET MVC So, assuming this the Insert to db will return any thing, like an ID, you must place this ID value in the ViewData or TempData since you're using RedirectToAction and then use it to call the function.. Adding Include Files to the Add Controller T4 Templates in ASP.NET MVC
    [AcceptVerbs(HttpVerbs.Post)]     public ActionResult Create(FormCollection collection)     {         int newID = InsertToDBAndReturnID();         ViewData["MyID"] = newID;         return View();     } 
And any where in the .aspx page this is used for the Create action:.
   <script type="text/javascript">        $(document).ready(function() {            // I have direct access to the "MyID" value from the action           // so I must utilize it to write any JavaScript with it           $('#'+<%: ViewData["MyID"] %>).click(function(){               alert('You clicked the control with the new ID');           });         });    </script> 
When the page is rendered, <%: ViewData["MyID"] %> is replaced with the actual value generated in the action..


58 out of 100 based on 53 user ratings 768 reviews

@