我与ASP.NET MVC的“预期”的错误

问题描述 投票:-1回答:1

我在编程新手。我不断收到这个预期的错误。

截图我连着显示了预期的错误是用红色标记:

指数:

@{
    ViewBag.Title = "Index";
}

<h2>Part 1 : Implement jQuery Datatable in ASP.NET MVC</h2>
<div style="width:90%; margin:0 auto;">
    <table id="myTable">
        <thead>
            <tr>
                <th>Employee Name</th>
                <th>Long Des</th>
                <th>Col Div</th>
                <th>Job Title</th>
                <th>Tenure Dec</th>
                <th>Emp Start</th>
            </tr>
        </thead>
    </table>
</div>
<style>
    tr.even {
        background-color: #F5F5F5 !important;
    }
</style>
@* Load datatable css *@
<link href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet" />
@* Load datatable js *@
@section Scripts{
    <script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#myTable').DataTable({
                "ajax": {
                    "url": "/home/loaddata",
                    "type": "GET",
                    "datatype": "json"
                },
                "columns": [
                        { "data": "L_FNAME", "autoWidth": true },
                        { "data": "COL_DIV_CODE", "autoWidth": true },
                        { "data": "JOB_TITLE", "autoWidth": true },
                        { "data": "TENURE_DEC_YR_MO", "autoWidth": true },
                        { "data": "EMPT_START_DATE", "autoWidth": true },
                        { "data": "BASE", "autoWidth": true },
                        { "data": "YTD", "autoWidth": true }
                ]
            });
        });
    </script>
}

Homecontroller.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCDatatable.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult loaddata()
        {
            using (MydatabaseEntities dc = new MydatabaseEntities())
            {
                var data = dc.Employees.OrderBy(a => a.L_FNAME).ToList();
                return Json(new {data = data}, JsonRequestBehavior.AllowGet);
            }
        }

问题是在家里控制器。这}导致预期的错误。

这是一个家庭作业。

asp.net-mvc
1个回答
0
投票

你已经错过了几个字符。算括号;注意到你怎么也比你有更多的{ } - 如果你发布的代码是你有什么(没有复制和粘贴错误),那么你永远不会关闭类或命名空间范围。该错误消息居然说} expected,这是告诉你,它预计看下一个},而是它找到该文件的末尾。

添加}结束类,另一个}结束命名空间范围,以及你的代码进行编译。

© www.soinside.com 2019 - 2024. All rights reserved.