Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to get CallerArgumentExpression from Blazor component Parameter

$
0
0

For our project we use multiple components which all have a Parameter Text and a Parameter Datafield like so:

[Parameter]public string Text { get; set; } = null!;[Parameter]public string DataField { get; set; } = null!;

We use the parameter Text to show the Value of the variable and we set in the DataField Parameter the Name of the variable like so:

<FormTextRow @bind-Value="_formModel.Name" DataField="@nameof(FormModel.Name)" />

We need the name of the variable to find the variable in the model to resolve all the given attributes. I would like to remove the DataField Parameter and let the component itself resolve the name of the given parameter.
This is then the expected way after the component can resolve the variable name:

<FormTextRow @bind-Value="_formModel.Name" />

I've found this example on a normal c# file: CallerArgumentExpression exampleBut I've no idea how to modify this to Blazor?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>