0

I have controller "Account", in which there is an action "UploadImage". This action can called from another actions.

I'm calling this action from another action "AddProduct" from "Product" Controller using Jquery.

Now what I want, Whenever my UploadImage action is invoked, I want to know the requesting controller or action name in UploadImage.

Like If I'm calling that action from AddProduct then, in UploadImage, ActionName name should be AddProduct.

I have done this

string actionName = this.ControllerContext.RouteData.Values["action"].ToString();
string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();

But This is always giving me

actionName : UploadImage

controllerName : Account

Solution 1 : I have option to pass the action name in ajax call but i don't want to do that. I want to get It In server side.

Amit Kumar
  • 5,888
  • 11
  • 47
  • 85
  • I'm guessing you want this to redirect back to the calling page? In which case you should pass the calling action/controller in as a `redirectUrl` parameter. – Steve Nov 30 '15 at 12:17
  • @Steve: No. actually I have perform some other task on the basis of requesting action name. – Amit Kumar Nov 30 '15 at 12:18
  • Are you using ajax calls to call this method from elsewhere ? – Dhrumil Nov 30 '15 at 12:19
  • @AmitKumar How do you call the first action from second action? Do you mean Performing an ajax call to second action while you are in view of first action? or do you mean a redirection? or something else? – Reza Aghaei Nov 30 '15 at 12:20
  • @MattMurdock: yes. I have option to pass the action name in ajax call but i don't want to do that. I want to get It In server side. – Amit Kumar Nov 30 '15 at 12:20
  • @RezaAghaei: yes, I'm using ajax call. and through ajax call I can call any action. – Amit Kumar Nov 30 '15 at 12:21
  • So you can pass @ViewContext.RouteData.Values["controller"] to the action as a parameter. – Reza Aghaei Nov 30 '15 at 12:21
  • @RezaAghaei: this is the last option to pass the action name in ajax call . Is there any other way so that I can get requesting page Url or action name – Amit Kumar Nov 30 '15 at 12:24
  • 2
    Just for a trying sake, check this : http://stackoverflow.com/questions/8830052/how-do-i-get-the-controller-and-action-names-from-the-referrer-uri – Dhrumil Nov 30 '15 at 12:26
  • @MattMurdock: This is what I'm looking for. Thank you very much. – Amit Kumar Nov 30 '15 at 12:31
  • @AmitKumar - Cool. Thanks. – Dhrumil Nov 30 '15 at 12:32

0 Answers0