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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:38:03+00:00 2026-05-27T09:38:03+00:00

For some reason, I cannot get an action to be hit. I am using

  • 0

For some reason, I cannot get an action to be hit. I am using RedirectToAction to pass the flow from one action to another, but it does not enter that function.

Here is the first action:

Public Function AddToCart(productId As Integer, returnUrl As String) As RedirectToRouteResult
    Dim product As Product = Me.Repository.Products _
        .FirstOrDefault(Function(p) p.ProductId = productId)

    If Not IsNothing(product) Then
        Me.Cart.AddItem(product, 1)
    End If

    Return RedirectToAction("Index", New With {.returnUrl = returnUrl})

End Function

That action gets hit (verified by a breakpoint). The subsequent action (Index) called via Return RedirectToAction("List", New With {.returnUrl = returnUrl}) never gets hit (also verified by a breakpoint.

This is the Index action function:

Public Function Index(returnUrl As String) As ViewResult
    Dim cartIndexViewModel As New CartIndexViewModel() With { _
        .Cart = Me.Cart, _
        .ReturnUrl = returnUrl _
    }
    Return View(cartIndexViewModel)
End Function

I am not sure it is relevant, but it might be worth to note that I created a View for the Index action, but later deleted and recreated it.

As a sanity check I then created another Action named List that is identical to the Index action, and this action does get hit (again, verified by a breakpoint)

This is the code of my controller in its entirety:

Imports SportsStore.Domain

Namespace SportsStore.WebUI
    Public Class CartController
        Inherits System.Web.Mvc.Controller

#Region "Properties"

Public Property Cart As Cart
    Get
        If IsNothing(Session("Cart")) Then
            Session("Cart") = New Cart()
        End If
        Return CType(Session("Cart"), Cart)
    End Get
    Set(value As Cart)
        Session("Cart") = value
    End Set
End Property

Private _Repository As IProductRepository
Private Property Repository() As IProductRepository
    Get
        Return _Repository
    End Get
    Set(ByVal value As IProductRepository)
        _Repository = value
    End Set
End Property

#End Region 'Properties

#Region "Constructors"

    Public Sub New(repository As IProductRepository)
        Me.Repository = repository
    End Sub

#End Region 'Constructors

#Region "Actions"
        '
        ' GET: /Cart

    Public Function AddToCart(productId As Integer, returnUrl As String) As RedirectToRouteResult
        Dim product As Product = Me.Repository.Products _
            .FirstOrDefault(Function(p) p.ProductId = productId)

        If Not IsNothing(product) Then
            Me.Cart.AddItem(product, 1)
        End If

'DOES NOT WORK
        'Return RedirectToAction("List", New With {.returnUrl = returnUrl})
'WORKS
        Return RedirectToAction("Index", New With {.returnUrl = returnUrl})

    End Function

    Public Function RemoveFromCart(productId As Integer, returnUrl As String) As RedirectToRouteResult
        Dim product As Product = Me.Repository.Products _
            .FirstOrDefault(Function(p) p.ProductId = productId)

        If Not IsNothing(product) Then
            Me.Cart.RemoveLine(product)
        End If

        Return RedirectToAction("Index", New With {.returnUrl = returnUrl})

    End Function

    Public Function List(returnUrl As String) As ViewResult
        Dim cartIndexViewModel As New CartIndexViewModel() With { _
            .Cart = Me.Cart, _
            .ReturnUrl = returnUrl _
        }
        Return View(cartIndexViewModel)
    End Function

    Public Function Index(returnUrl As String) As ViewResult
        Dim cartIndexViewModel As New CartIndexViewModel() With { _
            .Cart = Me.Cart, _
            .ReturnUrl = returnUrl _
        }
        Return View(cartIndexViewModel)
    End Function

#End Region 'Actions

    End Class
End Namespace

And here is the structure of the project:

Project Structure

What am I missing?

  • 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-27T09:38:04+00:00Added an answer on May 27, 2026 at 9:38 am

    Based on your code it appears you are redirecting to the Index action rather than the List action, from AddToCart().

    Return RedirectToAction("Index", New With {.returnUrl = returnUrl})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some classes that, for one reason or another, cannot be or need
I need to write a regex but for some reason i cannot get the
This seems like the most common relationship but for some reason I cannot get
For some reason, no matter how I go about it, I cannot get TortoiseSVN
It's a common problem, solved many times, but for some reason i cannot find
for some reason I cannot get any form to work correctly on my website,
For some reason I cannot get the error logging to work, I'm getting the
For some reason I cannot get my results set to restrict products that only
I was working from an example of an 'if' statement, but for some reason
I cannot for some reason get the wordpress /wp-admin pages to execute a simple

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.