You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术求助:如何移除表单代表端的Add an Owner按钮?

移除代表端表单的「Add an Owner」按钮解决方案

要在代表端(Model为Representative时)完全移除「Add an Owner」按钮,你需要修改按钮的渲染条件,仅当当前Model是Farm时才显示该按钮块。

修改后的代码:

@if (update)
{
    <div class="row">
        <div class="col d-grid gap-4 text-end align-self-end mt-3 me-3 ms-3 mb-3">
            <!-- 仅当Model是Farm时才渲染Add an Owner按钮 -->
            @if (Model is Farm)
            {
                @if (Model is Farm Owner && Owner != null)
                { 
                    <button type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" formnovalidate="formnovalidate" asp-route-Id="@((Farm)Model).Id" asp-action="AddOwner">@Lang["Add an Owner"]</button>
                }
                else
                {
                    <button disabled type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" formnovalidate="formnovalidate" asp-action="AddOwner">@Lang["Add an Owner"]</button>
                }
            }

            @if (Model is Farm)
            {
                <button type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" asp-action="Save">@Lang["Save"]</button>
                <button type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" asp-action="Submit">@Lang["Submit For Review"]</button>
            }
            @if (Model is Owner)
            {
                <button type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" asp-action="SaveOwner">@Lang["Save"]</button> 
            }
            @if (Model is Representative Representative && Representative.Id != null)
            {
                <button type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" formnovalidate="formnovalidate" asp-route-Id="@((Representative)Model).Id" asp-action="AddRep">@Lang["Add a Representative"]</button>
            }
            @if (Model is Representative)
            {
                <button type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" asp-action="AddRep">@Lang["Save"]</button>
            }
            @if (newEntity)
            {
                <button type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" asp-action="Add" formnovalidate="formnovalidate">@Lang["Reset"]</button>   
            }
            else
            {
                <button type="submit" class="btn btn-primary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" asp-action="ShowDetails" formnovalidate="formnovalidate">@Lang["Reset"]</button>
            }
            
            @if (delete)
            {
                <button type="submit" class="btn btn-secondary me-3 ms-3 ps-2 pb-1 pe-2 pt-1" formnovalidate="formnovalidate" asp-action="Delete" data-prompt="Are you sure you want to Delete the record?">@Lang["Delete"]</button>
            }
        </div>
    </div>
}

逻辑说明:

原代码中「Add an Owner」按钮的if-else块没有任何排除条件,导致不管当前Model是Farm还是Representative,都会渲染该按钮(要么启用要么禁用)。通过在外层包裹@if (Model is Farm)判断,只有当当前页面的Model是农场类型时,才会显示「Add an Owner」按钮,代表端页面便不会再出现这个按钮。

内容的提问来源于stack exchange,提问作者Christopher Blick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 07:25:54