Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 915823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:57:09+00:00 2026-05-15T17:57:09+00:00

After posting a form to database is it possible to call a jquery from

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:57:10+00:00Added an answer on May 15, 2026 at 5:57 pm

    No. You cannot call a jQuery function from an action. The way to do 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 that when the page fully loads, the function will be called.

    It is important to note that with MVC you have complete control of the HTML (JavaScript included) output and you should utilize that. While in WebForms its best to avoid using inline tags <% %>, in MVC, you’re expected to use them to generate the HTML you want.

    So, assuming that the Insert to db will return something, like an ID, you can place this ID value in the ViewData or TempData since you’re using RedirectToAction and then use it to call the function.

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            int newID = InsertToDBAndReturnID();
            ViewData["MyID"] = newID;
            return View();
        }
    

    And somewhere in the .aspx page that 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 can 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC Form, but the data from it needs to be
I am posting to the server using jquery ajax using $.post. After server returns
I am trying to do a HTTP POST from ASP.NET and JSP and it
I want to know if it's possible to cancel a post after posting a
Before posting my form I am checking the database to see if there are
I have a jquery Ajax call function that I use to submit form to
I've created two modules GWTAppAuth GWTApp when I try posting form from GWTAppAuth to
I'm posting a form from a partial view which is rendered via Html.RenderAction and
I am working on having data taken from a form submit to a database,
After posting a form having two fields named 'id' and 'url' I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.