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:

You can see that var1 is null, but ViewBag contains "Classes"

Why is this happening to me and what can I do to pass this value from a partial to editor template?

Was it helpful?

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
scroll top