mvc Field.SetValue()

mvc Field.SetValue()

montoyammontoyam Posts: 568Questions: 136Answers: 5

I know I can use render on the client side, but is there a way in the controller to use a function to return a value for a read only field.

                    .Field(new Field("Units")
                        .SetValue(

                            if (Fund == "All")  {
                             return this
                            } else { return that }
                         
                        )
                        .Set(false)
                    )

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,686Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Yes - have a GetValue as a simple string and then pass it through a get formatter to do the dynamic calculation (since that can be given as an anonymous function).

    Also, you'd want to use GetValue() in this case, not a set. Get in this context is reading from the server to the client (browser), while Set is what is set to the database.

    So

    new Field("Units")
      .GetValue("")
      .GetFormatter( (val, data) => {
        // ... some logic
      } )
    

    will hopefully do it for you.

    Allan

This discussion has been closed.