为什么ASP.NET Core在部分视图中脱离了OnClick标签/事件?

发布于 2025-01-29 10:27:36 字数 1325 浏览 2 评论 0原文

这驱使我上墙 - 任何急需和赞赏的帮助。

我有一个部分视图_policies.cshtml,带有一个带有on Click标签的按钮,该标签调用JavaScript函数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>

问题是我在Chrome(或Firefox,这似乎是框架问题)中构建和检查元素时OnClick标签只是不存在。如果我在开发工具中添加标签,它将调用正确的功能并执行该功能。我只是不明白为什么标签在建造时间被剥离。

我试图将onclick移至其他元素和divs,在部分和相同行为重复的情况下和外部。我根本没有抓住这一点。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文