c# - 预期为 "{"但发现为 ")"。在 Asp.Net MVC 5 中, block 语句必须包含在 "{"和 "}"中

标签 c# razor asp.net-mvc-5

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/

相关文章:

asp.net-mvc - MVC3 教程 HtmlHelper 不工作

javascript - asp.net mvc 加载第一个条目和其他条目 - 迟到

c# - 在 asp.net mvc Twitter OAuth2 登录后获取 oauth 凭据

asp.net-mvc - 如果在 web 配置中禁用 session 状态对 MVC 中的 ViewBag、ViewData 和 Tempdata 有何影响

javascript - 数据绑定(bind) : 'System.String' does not contain a property with the name 'numeroGuia'

c# - 放置后如何从 philips hue 桥获取 http json 响应

asp.net-mvc-3 - mvc razor 编辑器模板中的脚本

c# - 函数中的 Dispose 方法重要吗?

c# - .NET 集合和泛型如何工作?

javascript - html 的按键事件在移动设备上不起作用