I have controller PlayerController and actions inside: View, Info, List.
So on urls “/Player/View” i get result with default Layout.
I want to get result with different Layout on request “/External/View”.
How can i achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Although you can override the layout from the controller as has been suggested in another answer, in my opinion this means the controllers are getting just too involved in determining what the UI will be. Best to leave this purely to the Views to decide.
The closest to what you’re asking is to do this in your current
"~/Views/_ViewStart.cshtml":Where
"~/Views/_ExternalLayout.cshtml"is your alternative layout.Might want to check the leading
"/"is correct on there, I can’t remember if it is.If you put this in the existing _ViewStart, then any view that is being rendering in response to a url starting with
"/External"will use this new layout, otherwise the ‘normal’ one will be used.Another approach is to use the routing table to add a route value that can be used here to make a layout decision; but I’ve gone for this approach to keep it simple.