Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过单击链接将int值从视图传递到操作_C#_Asp.net Mvc - Fatal编程技术网

C# 通过单击链接将int值从视图传递到操作

C# 通过单击链接将int值从视图传递到操作,c#,asp.net-mvc,C#,Asp.net Mvc,我的视图中有一个关于表的for循环。我能够显示结果。但当我点击任何链接时。我得到一个空点异常。我发现这是因为循环完成了 @model List<MyMainModel> @using System.Collections; @using System.Web; @{ ViewData["Title"] = "Display"; } <h1>Display</h1> <table border=&quo

我的视图中有一个关于表的for循环。我能够显示结果。但当我点击任何链接时。我得到一个空点异常。我发现这是因为循环完成了

 @model List<MyMainModel>
@using System.Collections;
@using System.Web;
@{

    ViewData["Title"] = "Display";
}

<h1>Display</h1>
<table border="1" cellpadding="20" style="table-layout:fixed">
    <tr>
        <th>
            UserName
        </th>
        <th>
            PAssword
        </th>

        <th>
            Email
        </th>
        <th colspan="2">
            Options
        </th>
       
    </tr>
    @{ for (int i = 0; i < Model.Count; i++)
        {

        <tr>
            <td>
                @Model.ElementAt(i).USERNAME
            </td>
            <td>
                @Model.ElementAt(i).PASSWORD
            </td>

            <td>
                @Model.ElementAt(i).EMAIL
            </td>
            <td >
               <a href="@Url.Action("RemoveRow", "MyMain")">Remove</a>
            </td>
            <td>
                <a href="@Url.Action("EditRow", "MyMain")">Edit</a>
            </td>
        </tr>
            }
        }
</table>
    
@型号列表
@使用系统集合;
@使用System.Web;
@{
ViewData[“标题”]=“显示”;
}
展示
用户名
密码
电子邮件
选择权
@{for(int i=0;i

当我单击Remove时,我想将相应元素的ID传递回RemoveRow Action如何执行该操作

您的系统在哪里抛出
NullReferenceException
?您是否能够提供进一步的信息来帮助您回答?ID位于@Model.ElementAt(i).ID中,但由于循环已完成,b4用户可以单击Remove。i的值将变为null(因为循环已完成且显示了表格)。在运行时我不能唯一地标识这些行
@Url.Action("RemoveRow", "MyMain", new { id = i })