我无法绑定下拉列表值。也许我在代码中遗漏了一些东西。在这里,我附上了我的观看代码。
<tr>
<td>
<div class="form-group" style="margin-bottom:0px;">
@Html.DropDownList("ProofId", ViewBag.Idproofs as SelectList, new { @class = "form-control", id = "ProofType2", name = "ProofType2" })
</div>
</td>
<td>
<div class="form-group" style="margin-bottom:0px;">
@Html.TextBoxFor(x => x.EvidenceData[1].ProofNumber, new { @class = "form-control", id = "IdNumber2", name = "IdNumber2" })
</div>
</td>
<td>
<div class="form-group" style="margin-bottom:0px;">
@Html.TextBoxFor(x => x.EvidenceData[1].ProofImage, new { @class = "form-control", id = "ProofPic2", type = "file", name = "ProofPic2" })
<a href="~/images/ProofPics/@Model.EvidenceData[1].ProofImage" download title="Download Image" style="text-decoration:underline;"><i class="fa fa-download" aria-hidden="true"></i> Download Image</a>
</div>
</td>
</tr>
这是我的控制器代码:
public ActionResult EditProfile(string country)
{
if (!User.Identity.IsAuthenticated)
return new RedirectResult(Utility.Config("RedirectPath"));
var idprooflist = AccountManager.LoadProoftypes(country ?? "United States");
ViewBag.Idproofs = new SelectList(idprooflist, "ProofId", "ProofName");
UserRegistration UserProfileData = ProviderManagerBLL.GetProviderDetails(Convert.ToInt32(Session["UserID"].ToString()));
return View(UserProfileData);
}
答案 0 :(得分:0)
以下内容适合您:
<div class="form-group" style="margin-bottom:0px;">
@Html.DropDownList("ProofId", (SelectList)ViewBag.Idproofs, new { @class = "form-control", id = "ProofType2", name = "ProofType2" })
</div>
您正在使用ViewBag
将您的值传递给View
,您所要做的就是从中引用您想要的内容。你之前在做什么不会工作