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

  • Home
  • SEARCH
  • 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 8263053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:58:04+00:00 2026-06-08T03:58:04+00:00

I have the following in my Action: [AjaxException] public ActionResult DoSomething(sring someParam1, string someParam2)

  • 0

I have the following in my Action:

[AjaxException] 
public ActionResult DoSomething(sring someParam1, string someParam2) {

    //do whatever you need to do here, db etc
    return new EmptyResult();
}

in my html

<form id="search-frm" name="search-frm" action="@Url.Action("DoSomething", "MyActions")" method="post" >

    <input type="button" id="search-btn" value="search" class="btn" onclick="DoSomething();return false;" />
    <input type="text" name="param1" id="param1" />
    <input type="text" name="param2" id="param2" />
</form>

in my JS

function DoSomething() {  
   $("#search-frm").submit();
   return false;
}

When I click on the button, and after the controller action DoSomething is done, I get redirected to MyActions/DoSomething. Is there a way to not have that w/o using jquery $.ajax? I simply need to do something and not go away from the existing page.

  • 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-06-08T03:58:06+00:00Added an answer on June 8, 2026 at 3:58 am

    because your code is so. When you click on the button you are calling the DoSomething javascript function and inside that you are submitting the form. So it is same as the normal form submit(clicking on the submit button to submit). that is the reason it is redirecting (actually being posted to DoSomething action.

    If you do not want to navigate away from the current page, you may use ajax to do your posting and get result and stay in the same page. So i would make changes to your code like this

    1) Get rid of the OnClick event binding from the HTML markup

    2) Add this javascript which handles the form submit

    $(function(){
      $("#search-frm").submit(e){
    
       e.preventDefault();  // prevent the default form posting. Let's stay here
       $.post("@Url.Action("DoSomething","MyActions")",$("#search-frm").serialize(), function(data){
              //do something with the response data 
       });
    
      });     
    });
    

    Not sure why return EmptyResult from the Action method. You may need to return some valid response which indicates the status of the Action you are trying to perform.

    [HttpPost]
    public ActionResult DoSomething(string param1,string param2)
    {
      //do something 
       return Json(new 
                 { Status= true,
                   Message="Succesfully saved"
                 });      
    }
    

    You may keep a generic ViewModel to return such results and use that, instead of dynamically typing like above.

    public class OperationStatus
    {
      public bool Status  { set;get;}
      public string Message { set;get;}
    }
    

    and in your action method

    [HttpPost]
    public ActionResult DoSomething(string param1,string param2)
    {
      //do something 
      var res=new OperationStatus();
      res.Status=true;
      res.Message="Successfully Added";
       return Json(res);      
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the following MVC Action: [AcceptVerbs(HttpVerbs.Post)] public ActionResult GetDocument(int id, string fileName)
I have the following controller action: public ActionResult Details(string pk) { IEnumerable<ContentDetail> model =
I have the following action methods: public ActionResult ProfileSettings() { Context con = new
I have following code: public static void ProcessStep(Action action) { //do something here if
I have a controller with the following action code: public JsonResult CheckPasswordStrength(string password, string
I have the following controller Action: public ActionResult Details(int id) { Seguimiento seguimiento =
I have the following action method that initiated SelectList as follow:- public PartialViewResult Search(string
i have the following action method that calls a repository method:- public ActionResult Details(int
I have the following controller action: public ActionResult Edit(int id) { var news =
I have the following action: public class HomeController : Controller { public ActionResult Index(int?

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.