将Excel导入到数据库实现如下:

前台代码:

@model IEnumerable<Model.Student>
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script src="~/js/jquery.min.js"></script>
    <script>
        function ExcInput()
        {
            location.href = "/Home/ExcInput";
        }
    </script>
</head>
<body>
    <div>
        <form action="/Home/Execl" method="post" enctype="multipart/form-data">
            <input type="file" name="Exc" />
            <input type="submit" value="导入" />
        </form>

        <input type="submit" value="导出" onclick="ExcInput()"/>
        <table id="table">
            <tr>
                <th>编号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
            </tr>
            @foreach (var item in Model)
            {
                <tr>
                    <td>@item.id</td>
                    <td>@item.name</td>
                    <td>@item.age</td>
                    <td>@item.sex</td>
                </tr>
            }
        </table>
    </div>
</body>
</html>
View Code

相关文章: