skip to Main Content

I need to set a Field with a decimal? value, if doesn’t have value it should show the "-".

I tried use this code:

Field="@(nameof(this.DataDTO.EventDefaultValue > 0 ? this.DataDTO.EventDefaultValue.ToString("F2") : "-"))"/>

But doesn’t is possible convert, the Visual Studio show the error

enter image description here

I’m using the Blazor, together with DevExpress DxDataGridColumn component.

How can I to resolve this point? Someone can help me?

2

Answers


  1. Chosen as BEST ANSWER

    As it is the comment above the use of nameof() was wrong. I removed the nameof() and used DisplayTemplate component to set a field in my grid and pass a data of context.

    As I needed to make a condition verification the DisplayTemplate was a good solution.

    The code was this below:

     <DxDataGridColumn Caption="@Localizer["Valor Default"]"
                                  Field="eventDefaultValue">
                                  <DisplayTemplate>
                                      @{
                                        var summary = context as CostEventTypeSummaryDTO;
                                        if (summary.EventDefaultValue != null && summary.EventDefaultValue > 0)
                                        {
                                            <span>@summary.EventDefaultValue.Value.ToString("F2")</span>
                                        }
                                        else { <span>-</span> }
                                      }
                                  </DisplayTemplate>
                </DxDataGridColumn>
    

    And this result was this below:

    enter image description here


  2. nameof() method is used to get the name of a method, or a class for example. But you use it with some logic inside, so it will hit an error.

    The parameter Field is generally use – for example in the Telerik Library’s components – to target a field of a class. I am pretty sure it is exactly the same here, you wanna give the name of the field of your class that the column you set is reffered to. For example Field="@nameof(DataDTO.EventDefaultValue) will tell to Blazor "this column will display the EventDefaultValue field of the object".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search