Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果值为字符串,则ASP.NET Core SelectList不绑定_C#_Html_Asp.net Core Mvc - Fatal编程技术网

C# 如果值为字符串,则ASP.NET Core SelectList不绑定

C# 如果值为字符串,则ASP.NET Core SelectList不绑定,c#,html,asp.net-core-mvc,C#,Html,Asp.net Core Mvc,这里是风景 ViewData["ComponenteId"] = new SelectList(await GetComponentes(Geometria.MatrizId), "Nome", "Nome", Geometria.Componente); 百里香酮 无论什么,它都不会绑定,我不明白为什么值和文本基本上是相同的属性 这就是它在html中的呈现方式 <div class="form-row"> <div class="form-group col-m

这里是风景

ViewData["ComponenteId"] = new SelectList(await GetComponentes(Geometria.MatrizId), "Nome", "Nome", Geometria.Componente);

百里香酮
无论什么,它都不会绑定,我不明白为什么值和文本基本上是相同的属性

这就是它在html中的呈现方式

<div class="form-row">
    <div class="form-group col-md-4">
        <label asp-for="Geometria.Componente" class="control-label"></label>
        <select asp-for="Geometria.Componente" class="custom-select" asp-items="ViewBag.ComponenteId">
            <option value="">Selecione um Componente</option>
        </select>
        <span asp-validation-for="Geometria.Componente" class="text-danger"></span>
    </div>
</div>

百里香酮
M130291
M130559
M140004
M140040
SA00367A300
SS98940A100
更新

它没有绑定它的原因似乎是因为在我开始使用EntityFrameworkCore之前,该值就有空格。旧数据类型是varchar,因此无法识别它

<select class="custom-select input-validation-error" data-val="true" data-val-required="The Componente POE field is required." id="Geometria_Componente" name="Geometria.Componente" aria-describedby="Geometria_Componente-error" aria-invalid="true">
    <option value="">Selecione um Componente</option>
    <option value="M130291">M130291</option>
    <option value="M130559">M130559</option>
    <option value="M140004">M140004</option>
    <option value="M140040">M140040</option>
    <option value="SA00367A300">SA00367A300</option>
    <option value="SS98940A100">SS98940A100</option>
</select>