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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:12:24+00:00 2026-05-17T03:12:24+00:00

In an ASP.NET MVC application I have a CartController with this AddToCart action: public

  • 0

In an ASP.NET MVC application I have a CartController with this AddToCart action:

public RedirectToRouteResult AddToCart(Cart cart, decimal productId,
    string returnUrl)
    {
        Product product = productsRepository.Products
            .FirstOrDefault(p => p.prodID == productId);
        cart.AddItem(product);
        return RedirectToAction("Index", new { returnUrl });
    }

When a user submits a POST request (“Add to Cart” button) to this action from a plain ASP.NET MVC view, everything goes well: the Product is added to the Cart and the user is automatically redirected to a Cart/Index page.

If the product is submitted from a Silverlight app (which is inside an ASP.NET MVC view) it is successfully added to the Cart as well, but the there is no redirection in this case.

What is the problem? Maybe it is due to the fact that all requests from a Silverlight are asynchronous (if I’m not mistaken), and the request from a general ASP.NET MVC view is synchronous by nature? How it can affect the redirection?

In any case, how this problem could be solved?

Edited (added):

My code for sending a post request from a Silverlight app:

//first build a "paramstring" in the format "productId=126504" and then post it using this     
WebClient wc = new WebClient();
        wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
        wc.UploadStringAsync(new Uri("http://localhost:10930/Cart/AddToCart"), "POST", paramstring, "http://localhost:10930/Products");
  • 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-17T03:12:24+00:00Added an answer on May 17, 2026 at 3:12 am

    The WebClient you are using to send the POST request will automatically follow the redirects performed on the server and return the HTML and everything ends in the success callback. If you want to redirect the user browser to this page you shouldn’t use WebClient. You need javascript to submit a <form>. Silverlight allows you to execute javascript, so you could use it to dynamically generate and submit a form, or if the form already exists in the DOM set the values of the input fields and submit it.

    Here’s an example of how you could do this. Add the following javascript function to the same page hosting the Silverlight application:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
        function addToCart(productId, returnUrl) {
            var form = $(document.createElement('form'))
            .attr('action', '/products/addtocart')
            .attr('method', 'post')
            .append(
                $(document.createElement('input'))
                    .attr('type', 'hidden')
                    .attr('name', 'productId')
                    .val(productId)
            )
            .append(
                $(document.createElement('input'))
                    .attr('type', 'hidden')
                    .attr('name', 'returnUrl')
                    .val(returnUrl)
            );
            $('body').append(form);
            form.submit();
        }
    </script>
    

    And then inside your Silverlight application whenever you decide to invoke the POST action:

    HtmlPage.Window.Invoke("addToCart", "123", "http://example.com/someReturnUrl");
    

    You may add other parameters if necessary.

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

Sidebar

Related Questions

In an ASP.NET MVC application where I have the following model.. public class EventViewModel
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I have an ASP.NET MVC application using Authorization Attributes on Controllers and Actions. This
I have an asp.net mvc 3 application. In this application I have a reminder
I have this ASP.NET MVC application that I now want to separate out the
In my ASP .NET MVC application i have a link that refreshes the preview
I have one question; In my ASP.NET MVC web application have to do certain
I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7
I have an ASP.NET MVC application, when a user clicks on the submit button
I have an asp.net mvc application and i am trying to assign value to

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.