Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this action not being hit?
    primarykey
    data
    text
    <p>For some reason, I cannot get an action to be hit. I am using <code>RedirectToAction</code> to pass the flow from one action to another, but it does not enter that function. </p> <p>Here is the first action:</p> <pre><code>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 </code></pre> <p>That action gets hit (verified by a breakpoint). The subsequent action (Index) called via <code>Return RedirectToAction("List", New With {.returnUrl = returnUrl})</code> never gets hit (also verified by a breakpoint. </p> <p>This is the Index action function:</p> <pre><code>Public Function Index(returnUrl As String) As ViewResult Dim cartIndexViewModel As New CartIndexViewModel() With { _ .Cart = Me.Cart, _ .ReturnUrl = returnUrl _ } Return View(cartIndexViewModel) End Function </code></pre> <p>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. </p> <p>As a sanity check I then created another Action named <strong>List</strong> that is identical to the <strong>Index</strong> action, and this action does get hit (again, verified by a breakpoint)</p> <p>This is the code of my controller in its entirety:</p> <pre><code>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 </code></pre> <p>And here is the structure of the project:</p> <p><img src="https://i.stack.imgur.com/tmHUr.jpg" alt="Project Structure"></p> <p>What am I missing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload