Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MB 97 posts 365 karma points
    Sep 06, 2019 @ 00:11
    MB
    0

    Get Form from FieldViewModel ?

    I am creating a customised dropdown field using the FieldTypes in a custom Theme.

    FieldType.DropDownList.cshtml uses a FieldViewModel and I need to find the form that the fields are children of, because I need to look up some values using the Form-Name.

    Anyone got a clue on how to get a reference to the Form from the FieldViewModel of the field?

  • MB 97 posts 365 karma points
    Sep 06, 2019 @ 00:47
    MB
    0

    Ha! - answered my own question.

    Fortunately, the requirement is from the Themed FieldType being called from the Themed Form, as:

    Html.Partial(FormThemeResolver.GetFieldView(Model, f), f)
    

    So, I just needed to extend that out with a ViewDataDictionary and pass what I needed to the Themed FieldType as:

    Html.Partial(FormThemeResolver.GetFieldView(Model, f), f, new ViewDataDictionary { {"myKey", myValue }} )
    

    Perhaps not the most elegant of solutions, but it works for now.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies