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 8432579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:09:56+00:00 2026-06-10T06:09:56+00:00

I have an ajax.beginform() like this : @using (Ajax.BeginForm(Create_Product, Admin, new AjaxOptions() { OnFailure

  • 0

I have an ajax.beginform() like this :

@using (Ajax.BeginForm("Create_Product", "Admin", new AjaxOptions() { OnFailure = "alert(\"Error !!!\")", HttpMethod = "post"}))
{
//blah blah
}

It sends the form data to an ActionMethod called Create_Product…
Inside this ActionMethod, before I save the data as a new ‘product’ to the database, – inside a try/catch – I check to see whether the inserted product already exists or not. And if already exists, I need to return to the view AND trigger/run the OnFailure method of the ajax form 🙂

Is it possible ? how is it done ?

  • 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-10T06:09:57+00:00Added an answer on June 10, 2026 at 6:09 am

    Remove the Ajax Beginform and use the normal form

    @using(Html.Beginform("Create_Product","Admin"))
    {
      <input type="text" name="productName" />
      <input type="submit" id="saveNewProduct" />
    }
    

    And some javascript now to handle our Ajax Saving

    <script type="text/javascript">
      $(function(){
    
           $("#saveNewProduct").click(function(e){
              var item=$(this);
              e.preventDefault();
    
              $.post("@url.Action("Create_Product","Admin")",
                                    item.closest("form").serialize(),function(data){
                    if(data.Status=="Exist")
                    { 
                       alert("The Product already exist");
                    }
                    else if(data.Status=="Success")
                    {
                      alert("Saved Successfully");   
                    }
    
               });  
    
           });    
      });
    
    </script>
    

    Assuming your Action method Returns a JSON back in the below format, if it is successfully inserted

    {   "Status": "Success"   }
    

    If the Product already exist, It returns this

    {  "Status": "Exist"  }
    

    So your Action method can look like this

    [HttpPost]
    public ActionResult Create_Product(YourViewModel model)
    {
      try
      {
         //check product exist, if yes return the below commented JSON 
         // return Json(new { Status="Exist" });
        //else , Insert the data and Return Succes in JSON
         // return Json(new { Status="Success" });
      }
      catch(Exception ex)
      {
         // log error
        return Json(new { Status="Error" });
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page as follows: <% using (Ajax.BeginForm(AddAnswer,Marketplace,new AjaxOptions() {HttpMethod = POST })){
i have view which looks something like this : <% using (Ajax.BeginForm(new AjaxOptions {
I have an Ajax Form that looks like this: <% using (Ajax.BeginForm(Update, new AjaxOptions
I have a mvc2 application with a view like this <% using (Ajax.BeginForm(UserApprove, new
I have a form created using Ajax.BeginForm() <% using (Ajax.BeginForm(UpdateCompanyShop, CompanyShop, FormMethod.Post, new AjaxOptions
if I have an ajax form with AjaxOptions like this : (Ajax.BeginForm(new AjaxOptions {
I have an ajax form like so: <% using (Ajax.BeginForm(Comments, Comments, null, new AjaxOptions
I have a the following code @using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = update_panel, Url
I have something like this: I am using Ajax.BeginForm and its updatetargetid is a
This is the code in my partial view - @using (Ajax.BeginForm(SaveLayout, new AjaxOptions {

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.