MVC 5 for..loop ActionLink打破了html

时间:2017-12-05 13:06:18

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

ActionLink 在Foreach内部无法很好地呈现,当我删除它时,一切正常。

我的代码

<tbody>
    @foreach (TBaseModel record in Model.Records.List())
    {

        <tr>
            <td>@record["RowID"].value</td>
            <td>@record["Usr_Username"].value</td>
            <td>@record["Usr_FullName"].value</td>
            <td>@record["Usr_Sec_Level_Label"].value</td>
            <td>@record["Usr_Department_Label"].value</td>
            <td>@record["Usr_Active_Label"].value</td>
            <td>
                <a href="@Html.Action("Admin_New_User", "Admin", new { id = @record["id"].value })" class="btn btn-xs btn-success"><i class="fa fa-edit"></i> Edit </a>
            </td>
        </tr>
    }

</tbody>

问题是什么?

1 个答案:

答案 0 :(得分:1)

Html Action用于呈现视图而不是创建链接,请在此处查看:Html.Action And Html.RenderAction In ASP.NET MVC

您试图通过自己创建a而不是使用

<a href="@Url.Action("actionName", "controllerName", new { id = "<id>" })">
  Edit
</a> 

或只是使用

@Html.ActionLink("Edit", "ActionMethod", "Controller",new { id = "<id>" }, null)

将生成

<a href="/controllerName/ActionMethod/<id>">Edit</a>