C# DropDownList未修改绑定
我有一个C# DropDownList未修改绑定,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我有一个DropDownListFor,它绑定到模型中名为BinRangeSelection的字段。当我在此下拉列表中选择一个值时,BinRangeSelection值不会更改,它保持为空。这是我的下拉列表: @Html.DropDownListFor(m => m.BinRangeSelection, new SelectList(Model.BinRanges), "Select BIN Range", new { id = "BinRangesDropDown_start", @cl
DropDownListFor
,它绑定到模型中名为BinRangeSelection
的字段。当我在此下拉列表中选择一个值时,BinRangeSelection值不会更改,它保持为空。这是我的下拉列表:
@Html.DropDownListFor(m => m.BinRangeSelection, new SelectList(Model.BinRanges), "Select BIN Range", new { id = "BinRangesDropDown_start", @class = "five columns" })
和myBinRangeSelection
String:
private String _BinRangeSelection;
public String BinRangeSelection
{
get
{
return _BinRangeSelection;
}
set
{
System.Diagnostics.Debug.WriteLine("testing");
string[] rangeSplit = Regex.Split(value, " - ");
foreach (IdentifiBINConfiguration ibc in IdentifiBINConfigs)
{
if (ibc.LowerRange == rangeSplit[0] && ibc.UpperRange == rangeSplit[1])
{
IdentifiBINConfiguration = ibc;
}
}
_BinRangeSelection = value;
BinRangeSelection = value;
}
}
testing
语句永远不会打印到控制台,我已经放置了断点,set函数中没有任何内容被调用 通过在set
@DLeh内部设置BinRangeSelection
可以得到一个无限循环。我如何设置它而不调用无限循环?您同时设置了\BinRangeSelection
和BinRangeSelection
,只需设置第一个。第二个将重新调用同一个setter。您希望它何时启动setter?在你提交表格之前它不会启动。它不会在你选择下拉选项时触发。啊,有道理。谢谢编辑:在我提交表单之前它不会启动吗?好的,实际上这很有帮助。我想只要选择了一个值,就会调用它。