且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在一个视图中将表TD值从MVC3中的另一个视图中获取

更新时间:2022-01-20 02:50:50

例如下面是员工列表视图

For example below are the Employee Listing View
@model IEnumerable<mvcapplication1.models.employeetwo>

@{
    ViewBag.Title = "_employeeTwo";
}

<h2>_employeeTwo</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
//The  parameters of ActionLink are LinkText,ActionResult Name and parameter(your edited id) pass to the Edit ActionResult.Please make sure that the id we pass inside the ActionLink is same as the id in Edit Action Result
            @Html.ActionLink("Edit", "Edit", new { id=item.Id })
          
        </td>
    </tr>
}

</table>





当您单击编辑链接按钮重定向到同一控制器中的编辑ActionResult时。 />



When you click the edit link button redirect to the Edit ActionResult within the Same controller.

[HttpGet]
public ActionResult Edit(int id)
{
//do the business logic for getData by id and return the model
return View(model);
}





希望这有帮助



Hope this helps