Asp.net MVC - return to host controller when using partial views

I have a controller called "Parameters" which allows me to edit or view some parameters common to my object model. Creating / viewing is performed using several partial views - ShowParameters.ascx and CreateParameters.ascx.

I have several other controllers that use ShowParameters.ascx to display related parameters. It works great.

However, I have a problem with my partial view of CreateParameters.ascx. It invokes an action called CreateParameter in my Parameters controller to create the parameter. My problem is that I would like it to go back to the previous controller and display the Index view for that controller so that the user can see that this parameter is created.

How can my parameter controller determine which controller it should return to?

Thanks,

Tabby

0
source share
1 answer

You can pass the optional returnUrl parameter to the returnUrl action so that it redirects to this given URL. And in the partial view of CreateParameters.ascx you can pass the current name and action of the controller when creating the link.

Another option is to always redirect to Request.UrlReferrer inside your Request.UrlReferrer action.

+1
source

Source: https://habr.com/ru/post/1397807/


All Articles