For passing data between renderings I have seen this blog. Here they use below method to set data:

ContextService.Get().GetCurrent().ViewData.Add("_SharedModel", viewModel);

In Sitecore 9.0.1 I couldn't find this kind (GetCurrent().ViewData) of method to set viewdata.

How to pass data in Sitecore 9.0.1 or where can I find this method?


a) Adding proper references

You can find "ContextService" in Sitecore.Mvc namespace / assembly.

Just add below using to your razor view:

 using Sitecore.Mvc.Common; 

and in your project references add reference to "Sitecore.Mvc" assembly.

You have couple of options to achieve this. Two of them are below:

  1. Using nuget feed


from Sitecore Official nuget feed in version 9.0.171219 (that is correct one for Sitecore 9 Update 1). More information about nuget feeds can be found here -> https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/sitecore_public_nuget_packages_faq

enter image description here

  1. Copying Sitecore.Mvc.dll from bin folder to your shared lib folder in your project and reference it in csproj project file

b) Fixing GetCurrent method call

You should fix your code like this:

ContextService.Get().GetCurrent<ViewContext>().ViewData.Add("_SharedModel", viewModel);
  • But it dont have GetCurrent().ViewData property. – Anik Saha May 3 '18 at 12:56
  • I have updated my answer to fix this problem – Peter Procházka May 3 '18 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.