小编Nit*_*n B的帖子

如何动态地将值从提交按钮传递给mvc?

几天后我开始使用MVC,并且在学习MVC中的控制器和视图之间进行通信时遇到了很多问题

我有以表格形式显示员工列表的页面.

模型是类型IEnumerableEmployee Model

它有三个按钮,它们是Edit,Create,Delete,Details.

要求:
我使用了按钮,所有都应该是HTTP Post请求类型,因为我不希望用户使用URL请求直接访问它们.

这是我的观看代码:

@using (Html.BeginForm())
{
    <p>
        <input type="submit" name="CreateView" value="Create New(Post)" formaction="CreateView" formmethod="post" />
    </p>
    <table class="table">
        <tr>
            -------Headings of table-------
        </tr>
        @foreach (var item in Model)
        {
        <tr>
            <td>@Html.DisplayFor(modelItem => item.EmployeeName)</td>
            <td>@Html.DisplayFor(modelItem => item.EmployeeGender)</td>
            <td>@Html.DisplayFor(modelItem => item.EmployeeCity)</td>
            <td>@Html.DisplayFor(modelItem => item.DepartmentId)</td>
            <td>@Html.DisplayFor(modelItem => item.EmployeeDateOfBirth)</td>
            <td>
                <input type="submit" name="EditView" value="Edit(Post)" formaction="Edit" formmethod="post" /> |
                <input type="submit" name="DetailsView" value="Details(Post)" formaction="Details" formmethod="post" /> |
                <input …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-4

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

asp.net-mvc ×1

asp.net-mvc-4 ×1