ContestM ->模型属性
public SelectList EmployeeList { get; set; }
public int EmployeeId { get; set; }
Controller 操作
在主视图中单击按钮时,将执行此操作,并在处理来自数据库的下拉列表的数据后,我将值分配给下拉对象并尝试在部分 View 中显示该值
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 View (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>
}
无法找到我出错的地方。非常感谢任何帮助。
最佳答案
看起来此行末尾有一个额外的 )
:
@using (Html.BeginForm("AssignContest", "Contest", FormMethod.Post, new { id = "frmContestAssignContest" })))
顺便说一句,如果你想知道我是如何这么快找到它的,我只是使用浏览器的“查找”并搜索“)”,直到找到一个前面没有匹配的“(” ,并且它就在 {
之前,所以我知道就是那个。您应该了解错误消息的含义;很多时候它们很漂亮清晰且有帮助。
关于c# - 预期为 "{"但发现为 ")"。在 Asp.Net MVC 5 中, block 语句必须包含在 "{"和 "}"中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42696867/