C# 如何在dropdownlist MVC中选择值true

C# 如何在dropdownlist MVC中选择值true,c#,model-view-controller,html.dropdownlistfor,list.selectedvalue,C#,Model View Controller,Html.dropdownlistfor,List.selectedvalue,我在dropdownlist选择值中有问题 查看 @Html.DropDownList("QuestionType", (IEnumerable<SelectListItem>)ViewData["questiontype"], new { id = "QuestionType", @style = "max-width: 200px;width: 200px", @OnChange = "HideForm(this)", @class = "form-control" }) @H

我在dropdownlist选择值中有问题

查看

@Html.DropDownList("QuestionType", (IEnumerable<SelectListItem>)ViewData["questiontype"], new { id = "QuestionType", @style = "max-width: 200px;width: 200px", @OnChange = "HideForm(this)", @class = "form-control" })
@Html.DropDownList("QuestionType", ViewData["questiontype"] as SelectList,  new { id = "QuestionType", @style = "max-width: 200px;width: 200px", @OnChange = "HideForm(this)", @class = "form-control" })

为什么这个代码有效,为什么以前的代码无效?我很困惑…

不确定您是否有强类型视图,但您可以使用

    DropdownlistFor(model=>model.QuestionType, selectlistItem)
然后在控制器集中

model.QuestionType to 2;
然后

return View(model);

很抱歉我不使用stronglytyped视图。我只使用绑定到dropdownlist的viewdata。我已经编辑了我的问题,我的代码在修改之前(不是工作)和修改之后(工作)都很混乱。你能帮忙吗?
model.QuestionType to 2;
return View(model);