how to get current document context in view (index.cshtml)?

Muhammad Kaleem asked on June 5, 2019 11:47

how can i get current document context in my view file, i'm facing null reference exception by using this

if (CMS.DocumentEngine.DocumentContext.CurrentDocument.DocumentName != null)
    {
        currentDocumentName = CMS.DocumentEngine.DocumentContext.CurrentDocument.DocumentName;
    }

please suggest

thanks

Recent Answers


UNRVLD Agency answered on June 5, 2019 14:40 (last edited on June 5, 2019 14:40)

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on June 5, 2019 14:41

Unfortunally, there is no way of doing this out-of-the-box. You would need to code it in the controller to get the current context page and include this data into your view model. Please refer to the code from the HomeController of Dancing Goat example website:

var home = mHomeRepository.GetHomePage();

You can add some more properties into your view model and populate these from home object. Basically, this is the way of doing things with Kentico 12 MVC approach.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.