DropDownListFor 表单提交未触发
DropDownListFor Form Submit not firing
我有一个过滤器下拉列表用于:
@Html.DropDownListFor(x => x.selectedDateFilter,
new SelectList(Model.bydatefilter, "id", "dt", Model.selectedDateFilter),
"By Date",
new { onchange = "this.form.submit();", @class = "form-control" })
当我更改选择时,我什么也没得到。
这是页面来源:
<select class="form-control"
data-val="true"
data-val-number="The field selectedDateFilter must be a number."
data-val-required="The selectedDateFilter field is required."
id="selectedDateFilter" name="selectedDateFilter"
onchange="this.form.submit();"><option value="">By Date</option>
<option value="1">April-2015</option>
<option value="2">May-2015</option>
<option value="3">June-2015</option>
<option value="4">July-2015</option>
<option value="5">August-2015</option>
<option value="6">September-2015</option>
<option value="7">October-2015</option>
<option value="8">November-2015</option>
<option value="9">December-2015</option>
<option value="10">January-2016</option>
</select>
我注意到关于这个主题的所有答案都使用 DropDownList 而不是 'for'。是否有一个原因?为什么控件没有 post 返回?
编辑:我传递的模型是一个设置为零的整数。想法是它将在 post.
之后按索引设置所选项目
public int selectedDateFilter { get; set; }
selectedVenueFilter = 0;
这是在源中创建以下错误的地方:
data-val="true"
data-val-number="The field selectedDateFilter must be a number."
@Html.DropDownListFor(x => x.selectedDateFilter,
new SelectList(Model.bydatefilter, "id", "dt", Model.selectedDateFilter),
"By Date",
new { onchange = "this.form.submit();", @class = "form-control" })
我检查了x.selectedDateFilter = 0的值。我也尝试将其设置为1,但仍然错误。
那么你需要做如下:
@Html.DropDownListFor(x => x.selectedDateFilter,
new SelectList(Model.bydatefilter, "id", "dt", Model.selectedDateFilter),
"By Date",
new { onchange = @"this.form.submit();", @class = "form-control" })
您需要在 this.form.submit();
之前附加 @
我有一个过滤器下拉列表用于:
@Html.DropDownListFor(x => x.selectedDateFilter,
new SelectList(Model.bydatefilter, "id", "dt", Model.selectedDateFilter),
"By Date",
new { onchange = "this.form.submit();", @class = "form-control" })
当我更改选择时,我什么也没得到。
这是页面来源:
<select class="form-control"
data-val="true"
data-val-number="The field selectedDateFilter must be a number."
data-val-required="The selectedDateFilter field is required."
id="selectedDateFilter" name="selectedDateFilter"
onchange="this.form.submit();"><option value="">By Date</option>
<option value="1">April-2015</option>
<option value="2">May-2015</option>
<option value="3">June-2015</option>
<option value="4">July-2015</option>
<option value="5">August-2015</option>
<option value="6">September-2015</option>
<option value="7">October-2015</option>
<option value="8">November-2015</option>
<option value="9">December-2015</option>
<option value="10">January-2016</option>
</select>
我注意到关于这个主题的所有答案都使用 DropDownList 而不是 'for'。是否有一个原因?为什么控件没有 post 返回?
编辑:我传递的模型是一个设置为零的整数。想法是它将在 post.
之后按索引设置所选项目public int selectedDateFilter { get; set; }
selectedVenueFilter = 0;
这是在源中创建以下错误的地方:
data-val="true"
data-val-number="The field selectedDateFilter must be a number."
@Html.DropDownListFor(x => x.selectedDateFilter,
new SelectList(Model.bydatefilter, "id", "dt", Model.selectedDateFilter),
"By Date",
new { onchange = "this.form.submit();", @class = "form-control" })
我检查了x.selectedDateFilter = 0的值。我也尝试将其设置为1,但仍然错误。
那么你需要做如下:
@Html.DropDownListFor(x => x.selectedDateFilter,
new SelectList(Model.bydatefilter, "id", "dt", Model.selectedDateFilter),
"By Date",
new { onchange = @"this.form.submit();", @class = "form-control" })
您需要在 this.form.submit();
@