0
<InputText class="input-checkbox100" id="ckb1" name="validateUSPSAddress" disabled="@true" @bind-Value="_model.CheckUSPSValidation" />

In my model, I have defined CheckUSPSValidation as

 public bool CheckUSPSValidation { get; set; }

The error I receive is the following. I don't understand why it's trying to convert bool to string

Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'bool' to 'string' 219 N/A

4
  • use CheckUSPSValidation.ToString() Commented Aug 8, 2021 at 14:27
  • 1
    Why not <InputCheckbox> ? Commented Aug 8, 2021 at 15:41
  • I agree with Brian, you are using the wrong UI component for a boolean. Commented Aug 8, 2021 at 15:55
  • Don't mess with basic inputs. Browsers, especially phone browsers, often have special components for html input, and by-passing them like this could have unfortunate consequences for phone users. Commented Aug 9, 2021 at 19:45

1 Answer 1

1

You have to convert it to bool and back to string. Binding has to be with a string:

<EditForm Model="mod">
  <InputText @bind-Value="@mod.checkString"/>
</EditForm>
Value: @mod.check
@code {

MyModel mod = new();
class MyModel
{
    public bool check { get; set; }
    public string checkString{get=>check.ToString();
    set{
        if(Boolean.TryParse(value, out bool val))
        check = val;
    }
    }
}
}

Working demo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.