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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:56:54+00:00 2026-06-07T09:56:54+00:00

I have an Add to Cart button that if the browser supports JS +

  • 0

I have an “Add to Cart” button that if the browser supports JS + Ajax (and doesn’t have it turned off) it POSTS using Ajax back to the site, however if they don’t support it, or have it turned off it does the manual style POST.

What I am hoping to accomplish is two views – one when the user posts back using a regular POST and one when it comes from a AJAX POST. That way I can show an in-line message (partial) or a full screen.

I would prefer not having to duplicate the controller/action code twice, it just seems non-elegant.

Is there any recommended solutions or patterns for this type of issue?

  • 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-07T09:56:55+00:00Added an answer on June 7, 2026 at 9:56 am

    John,

    You can use the IsAjaxRequest method on the request to determine this. You would apply it to your scenario thusly:

    public ActionResult AddToCart(YourCartViewmodel cartViewmodel)
    {
         if (ModelState.IsValid)
         {
             // do the standard/common db stuff here
             if(Request.IsAjaxRequest())
             {
                 return PartialView("myPartialView");
             }
             else
             {
                 return View("standardView");
             }
         }
         /* always return full 'standard' postback if model error */
         return View(cartViewmodel);   
    }
    

    altho not perhaps giving a complete solution, this should give you a good start…

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

Sidebar

Related Questions

I have a button, Add to Cart which sends an ajax request when clicked.
I have an add this button on the website that is rendering a border
I have a button like this: <input type=submit id=product_197_submit_button class=wpsc_buy_button name=Buy value=Add To Cart>
I have a button with a rollover using jquery ui to add the class
I have written this code for add cart to payment. while clicking buttons that
I have the following button : <%= button_to 'Add to Cart', line_items_path(:product_id => product),
I have an ecommerce site that, every time someone clicks on Add to Pallet
I have a shop site where users can add/edit to a cart from a
REVISED QUESTION : We have tracked this down to a custom add to cart
I have a JTable called Cart where user can add products before buying them.

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.