Search code examples
asp.net-mvcasp.net-corerazor

How to change all my textbox input letters to uppercase in mvc razor page?


Heres my TextBox

<div class="col-md-10">
                        @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control", @placeholder = "First Name"} })
                        @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
                    </div>

Solution

  • You can use js:

    $(function () {
            $("input").each(function () {
                $(this).val($(this).val().toUpperCase());
            })
        })
    

    It will change all the inputs' values to uppercase when page loaded.If you want to change all my textbox input letters to uppercase when input lose focus,you can use:

     $("input").change(function () {
            $(this).val($(this).val().toUpperCase());
        })