ContestM - >模型的属性
public SelectList EmployeeList { get; set; }
public int EmployeeId { get; set; }
控制器操作
在按钮上单击主视图时,此操作正在被触发,在处理数据从db下拉后,我将值分配给下拉对象并尝试在部分视图中显示该值
public ActionResult AssignContest()
{
try
{
int id = 3;
var res = ContestVM.getTLEmployees(id).ToList();
var eList = new ContestM();
eList.EmployeeList = new SelectList(res, "EmployeeId", "FirstName");
return PartialView("Assign", new ContestM() { EmployeeList = eList.EmployeeList });
}
catch (Exception ex)
{
ViewData["error"] = ex.Message.ToString();
return View("~/Views/Shared/LogoutOrInvalid.cshtml");
}
}
我的Razor视图(assign.cshtml)
@model Performance.Launcher.Models.ContestM
@using (Html.BeginForm("AssignContest", "Contest", FormMethod.Post, new { id = "frmContestAssignContest" })))
{
//var emplistdata= ViewData["employeesList"];
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Contest</h4>
<hr />
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.ContestId)
<div class="form-group">
@Html.LabelFor(model => model.EmployeeId, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.EmployeeId, Model.EmployeeDet, "Choose...", new { htmlAttributes = new { @class = "form-control col-md-2" } })
//@Html.DropDownList("dropdown1", ViewData["employeesList"])
//@Html.ValidationMessageFor(model => model.EmployeeId)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
无法找到我出错的地方。非常感谢任何帮助。
答案 0 :(得分:4)
看起来你在这一行的末尾有一个额外的)
:
@using (Html.BeginForm("AssignContest", "Contest", FormMethod.Post, new { id = "frmContestAssignContest" })))
顺便说一下,如果你想知道我怎么这么快弄清楚,我只是用我的浏览器的“查找”并搜索“)”,直到找到一个没有匹配的“(”之前) ,和它就在{
之前,所以我知道那就是那个。你应该听取他们的意思的错误信息;很多时候他们非常清楚和有帮助