简体   繁体   English

Null 检查破坏了我的 Blazor wasm web 应用程序的 UI

[英]Null checks ruin the UI of my Blazor wasm web app

When I add a null check on a page, it messes with the UI, especially some of the bootstrap components of that page.当我在页面上添加 null 检查时,它会与 UI 混淆,尤其是该页面的一些引导组件。

For example:例如:

@if(Summary is null){
    <Spinner />
}
else
{
    <div class="col-4">
        <label class="mr-3 col-2 mt-3">My dropdown</label>
        <select class="form-control bootstrap-select col" id="kt_form_status">
            <option value="Today">Today</option>
            <option value="7 days">7 days</option>
            <option value="4 weeks">4 weeks</option>
        </select>
    </div>
}

displays this显示这个

在此处输入图像描述

and:和:

<div class="col-4">
        <label class="mr-3 col-2 mt-3">My dropdown</label>
        <select class="form-control bootstrap-select col" id="kt_form_status">
            <option value="Today">Today</option>
            <option value="7 days">7 days</option>
            <option value="4 weeks">4 weeks</option>
        </select>
    </div>

gives me this:给了我这个:

在此处输入图像描述

What am I missing or what can I do to stop/workaround this?我错过了什么或者我能做些什么来停止/解决这个问题?

Here's the code you've given us in a standard Blazor template Index page.这是您在标准 Blazor 模板索引页面中提供给我们的代码。

I've:我有:

  1. Added a button to toggle Summary from null to a value.添加了一个按钮,用于将摘要从 null 切换到一个值。
  2. Wrapped your column divs in rows to space out correctly.将列 div 包装成行以正确间隔。

Both look the same to me.两者在我看来都一样。

In your images there's two different styles applied, therefore there must be something your not showing us that is causing your problem.在您的图像中,应用了两个不同的 styles,因此一定有一些您没有向我们展示的东西导致了您的问题。

@page "/"

<PageTitle>Index</PageTitle>

<div class="m-3 p-2 text-end">
    <button class="btn btn-primary" @onclick=Update>Update</button>
</div>

@if (Summary is null)
{
    <alert class="alert alert-danger">
        Summary is Null!
    </alert>
}
else
{
    <div class="row">
        <div class="col-4">
            <label class="mr-3 col-2 mt-3">My dropdown</label>
            <select class="form-control bootstrap-select col" id="kt_form_status">
                <option value="Today">Today</option>
                <option value="7 days">7 days</option>
                <option value="4 weeks">4 weeks</option>
            </select>
        </div>
    </div>
}

<div class="row">
    <div class="col-4">
        <label class="mr-3 col-2 mt-3">My dropdown</label>
        <select class="form-control bootstrap-select col" id="kt_form_status">
            <option value="Today">Today</option>
            <option value="7 days">7 days</option>
            <option value="4 weeks">4 weeks</option>
        </select>
    </div>
</div>

@code {
    private string? Summary;

    private void Update()
         => Summary = Summary is null ? "Not Null" : null;
}

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM