3

I don´t see how to preselect a dropdown using Super Simple View Engine.

My model has a property datatype which is a number and I want to preselect this in the dropdown.

As I see from documentation conditionals only work on boolean values. So using something like this in my view does not work:

<option value="1" @If.datatype==1 selected @EndIf>number</option>
<option value="2" @If.datatype==2 selected @EndIf>string</option>
...

Is there any way to achieve what I´m trying to do? Or do I have to use another view engine?

jens_h
  • 377
  • 3
  • 13

1 Answers1

0

What I did to get around this limitation of SSVE was to add a bool property to the class I used for the dropdown, which I then set after retrieving from the database.

public class MySettingsViewModel
{
    public int StateId { get; private set; }
    public List<StateSetting> States { get; set; }
    public void SetState()
    {
        if (StateId <= 0 || States == null || !States.Any())
        {
            return;
        }
        var state = States.First(x => x.Id == StateId);
        if (state == null) { return; }
        state.IsSelected = true;
    }
    public class StateSetting : State
    {
        public bool IsSelected { get; set; }
    }
}
pdwetz
  • 841
  • 1
  • 9
  • 19