Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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
.net 从下拉列表中选择的值在模型页面中为空_.net_Forms_Asp.net Core - Fatal编程技术网

.net 从下拉列表中选择的值在模型页面中为空

.net 从下拉列表中选择的值在模型页面中为空,.net,forms,asp.net-core,.net,Forms,Asp.net Core,我正在尝试在Razor Pages.NetCore中创建一个表单,下一步将在其中发生: 用户从日期选择器中选择一个日期 基于该日期,一些值将填充下拉列表 用户从下拉列表中选择一个值,该值进入数据库 问题在于,提交表单时,从下拉列表中选择的值为空(尽管在UI中显示并可以选择下拉列表值) 在html中 @section Scripts { <script> $("#SelectDate").on("change", function (

我正在尝试在Razor Pages.NetCore中创建一个表单,下一步将在其中发生:

  • 用户从日期选择器中选择一个日期
  • 基于该日期,一些值将填充下拉列表
  • 用户从下拉列表中选择一个值,该值进入数据库
问题在于,提交表单时,从下拉列表中选择的值为空(尽管在UI中显示并可以选择下拉列表值)

在html中

@section Scripts {
<script>
    $("#SelectDate").on("change", function () {
            var myDate = $(this).val();

            $("#select").empty();
            $("#select").append("<option value=''>select </option>");
            $.getJSON(`?handler=Date&date=${myDate}`, (data) => {
                $.each(data, function (i, item) {
                    $("#select").append("<option value='"  + "'>" + item.value + "</option>");
                });
            });
        });
</script>
}

<form method="post">
<div class="form-group">
       <label asp-for="SelectDate" class="control-label"></label>
       <input asp-for="SelectDate" class="form-control" />
       <span asp-validation-for="SelectDate" class="text-danger"></span>
 </div>

<select id="select" asp-for="SelectedValue"></select>

<div class="form-group button-position col-md4">
      <input type="submit" name="Submit" value="Submit" />
</div>
</form>

只需像这样更改代码

$("#select").append(""<option value='" + item.value + "'>"  + "'>" + item.value + "</option>");
$(“#选择”).append(“+”>“+item.value+”);
$("#select").append(""<option value='" + item.value + "'>"  + "'>" + item.value + "</option>");