Passing additional data in a ViewBag to the EditorTemplate from the Partial
-
14-11-2019 - |
Question
I have a partial view:
@ModelType ProjectCreateViewModel
@Code
Dim vdd = New ViewDataDictionary()
vdd.Add("Classes", "template")
End Code
@Html.EditorFor(Function(m) m.Project.InvoiceScheduleBasedOnDates, vdd))
In this partial view I create new ViewDataDictionary to pass additional data to my editor. In the editor I access ViewBag.Classes and its value is null. However, when I debug I can see that the ViewBag contains "Classes" key. Here a screen dump:
Why is this happening to me and what can I do to pass this value from a partial to editor template?
Solution
You could pass it as an anonymous object:
@ModelType ProjectCreateViewModel
@Html.EditorFor(Function(m) m.Project.InvoiceScheduleBasedOnDates, New With { .Classes = "template" })
and in your template:
@Modelype InvoiceDate
@Code
Dim var1 = ViewBag.Classes
...
End Code
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow