在我看来,当我这样做时,下拉列表会正确显示 -
@Html.DropDownListFor(m => m.SelectedEstimateState, Model.EstimateStateList.ToSelectList(c => c.Value, c => c.Text), new { });
但不是在我这样做的时候 -
@{
Html.DropDownListFor(m => m.SelectedEstimateState, Model.EstimateStateList.ToSelectList(c => c.Value, c => c.Text), new { });
}
两者有什么区别?
答案 0 :(得分:1)
这是code block expression
,用于评估表达式。但它没有写出来。有关更多信息,请查看剃刀语法Razor syntax和web-programming-using-the-razor-syntax
@{
Html.DropDownListFor(m => m.SelectedEstimateState, Model.EstimateStateList.ToSelectList(c => c.Value, c => c.Text), new { });
}
以下将写出内容(基本上与带编码的response.write()相同)
@Html.DropDownListFor(m => m.SelectedEstimateState, Model.EstimateStateList.ToSelectList(c => c.Value, c => c.Text), new { });