ASP.NET MVC Redirect to action without physical redirection

Is it possible in any other way to perform another action in another controller from the filter of actions, actions, or in any other way without physical redirection.

The reason for this is that I have a dynamic paging system where the user will load the URL, for example,

/1/some-page-title 

This URL is mapped to the Home controller and the Element action, this action then loads the row from the database, where the element identifier is "1". Depending on the data about an element from the database, the page will be displayed as a contact form, image gallery, etc. Now I could display the paths this way

 /Page/1/some-title/ will render a normal html page, /Contact/1/some-title/ will render a contact form /Gallery/1/some-title/ will render a gallery 

But I would prefer the paths to be simple.

+7
source share
2 answers

There are problems with this answer, I haven’t done anything with ASP MVC for a long time, so I really don’t know what the problems are. Sorry, I can’t delete the accepted answer.
So, I am amazed at the answer, as it was, if you can really answer this question or make it better, please do it.

Yes, very simple :)

Say that you are in the action of controller C. You want to "redirect" to the action of the controller BB, just call another controller action from the current one, returning the result.

 public ActionResult A() { return BZ() } 

+11
source

You may be looking for Html.RenderAction or Html.Action . However, they are used in the view, not in the controller.

0
source

All Articles