How to pass data to a partial view of a Block List Item
I used to pass data by using the ViewDataDictionary. But in v9 for some reason it isn't working anymore. I'm getting this error: 'ViewDataDictionary' does not contain a constructor that takes 0 arguments
Does anyone have a solution on how to use the ViewDataDictionary in v9 or how to pass data in another way to my partial?
I think I actually found the problem, it's because I'm using another Block List editor in my Block List editor to build up a grid of items. So it's using the Default.cshtml twice to render since it's a nested Block List editor. Do you have any solutions for this?
If you have several partial views included on your main view the ViewData is cleared on each call. The issue is when you have a partial view call inside a partial view. ViewData isnt cleared so if you are passing ViewData to each partial with the same keys you get this error.
If you add:
ViewData.Clear()
before you call the partial you wont get this error message.
How to pass data to a partial view of a Block List Item
I used to pass data by using the ViewDataDictionary. But in v9 for some reason it isn't working anymore. I'm getting this error: 'ViewDataDictionary' does not contain a constructor that takes 0 arguments
Does anyone have a solution on how to use the ViewDataDictionary in v9 or how to pass data in another way to my partial?
Kind regards, Jonathan
Hi Jonathan,
In .net core you need to pass ViewData in the constructor
I already found that solution but then I'm getting this error:
Since it is in a loop to run over the block list items.
I think I actually found the problem, it's because I'm using another Block List editor in my Block List editor to build up a grid of items. So it's using the Default.cshtml twice to render since it's a nested Block List editor. Do you have any solutions for this?
Kind regards, Jonathan
Hi Jonathan,
If you have several partial views included on your main view the ViewData is cleared on each call. The issue is when you have a partial view call inside a partial view. ViewData isnt cleared so if you are passing ViewData to each partial with the same keys you get this error.
If you add:
before you call the partial you wont get this error message.
Cheers,
Marc
Perfect! Thanks a lot for your help!
Hi Jonathan,
Can you mark last answer as the solution to help other folks that come across this?
Cheers,
Marc
How do you actually retrieve the value of the ViewData in the partial?
Got it! ViewData["backgroundColor"]
is working on a reply...