asp.net-mvcmodel-view-controller

ASP.NET MVC Finding out the caller to a method when !ModelState.IsValid


I have action method on my "CartController" an AddtoCart that returns an ActionResult. The problem I'm having is that I post from antoher controller to the AddtoCart the Id of the product i want to add, then move on. I have no problem with the validation; however, it's when I want to redirect to the View that called the Action when the !ModelState.IsValid, that I don't know who called me (or where to find it).

It is possible that several different controllers may post to the method. Is there something in the ViewData that I can use to findout who called my Action Method?


Solution

  • Sounds to me like you are after:

    Request.UrlReferrer
    

    Let me know if you're not.