How do I store data for drop-down select fields

Posted 3 years ago by metab0i
0

Is there any alternative way of providing input data for drop-down select fields apart from having them directly in the form? This is how i have it now:
It just doesn't feel right and i have a hunch that this is bad practice. I'd highly appreciate a pointer or advice on how to do this properly, thank you

<InputSelect class="form-control" id="PWIO" @bind-Value="@newInjury.LAWIModel.PlaceWhereInjuryOccured" @onkeyup="@(() => {HideUnhideField("PlaceWhereInjuryOccured");})" @onclick="@(() => {HideUnhideField("PlaceWhereInjuryOccured");})">
                <option value="">Select Mechanism of Injury...</option>
                <option value="Overuse">Overuse</option>
                <option value="Struck by or collision with another playeror object">Struck by or collision with another playeror object</option>
                <option value="Collision with fixed object/equipment">Collision with fixed object/equipment </option>
                <option value="fall/slip/trip/ stumble on same level">fall/ slip/trip/ stumble on same level</option>
                <option value="Sudden or rapid acceleration and deceleration">Sudden or rapid acceleration and deceleration</option>
                <option value="Jumping, including landing from jump">Jumping, including landing from jump</option>
                <option value="Temperature related">Temperature related</option>
                <option value="Other">Other</option>
                <option value="Unknown">Unknown</option>
            </InputSelect>
            
  • 1

    I don't know if I would necessarily consider it bad practice, especially if the values will rarely change. If it needs updated from time to time, you may want to store the values in a database and populate the options in some way like:

    ...
    @foreach(var place in places)
    {
    	<option value="@place.description">@place.description</option>
    }
    ...

    You'd also want to add code to make sure places isn't null before trying to use it.

    Posted 3 years ago by selliott
Someone is typing...

Post a Reply

You must be logged in to add a new post.
Number of online users: 0
An error has occurred. This application may no longer respond until reloaded. Reload 🗙