'Why is ASP.NET Core stripping out onclick tag/event in a partial view?

This is driving me up the wall - any help much needed and appreciated.

I have a partial view _Policies.cshtml with a button that has an onclick tag that calls the JavaScript function changeCostCentreNumber():

<div class="row">
    @if (User.Claims.Any(x => x.Value.Equals(Site.Infrastructure.Common.MemberType.IsScheme.ToString())))
    {
        <div class="form-group">
            <div class="col-md-4">
                <label for="costCentreChange" class="form-label">Change scheme cost centre number</label>
                <input id="costCentreChange" class="search-icon form-control" type="text" name="searchFilter" placeholder="" value="" pattern="[a-zA-Z0-9 ]+" maxlength="20"/>
            </div>
            <div class="col-sm-12">
                <input class="btn button button-green" type="submit" id="costCentreNumberSubmitBtn" value="Submit" onclick="changeCostCentreNumber()"/>
            </div>
            <div class="alert-info alert" id="costCentreNumberChangeAlert" style="display:none">
                The cost centre number has been updated successfully.
            </div>
        </div>
    }
</div>

The problem is when I build and inspect the element in Chrome (or Firefox, this seems to be a framework issue) the onclick tag is just not there. If I add the tag in Dev Tools it calls the correct function and does what it's supposed to. I just don't understand why the tag is being stripped out at build time.

I've tried to move the onclick to other elements and divs, inside and outside the condition in the partial and the same behaviour repeats. There's something about this I am simply not grasping.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source