繁体   English   中英

Action 方法参数为 Null 虽然它不应该是

[英]Action Method Parameter is Null Although it should not be

我检查了类似问题的其他答案,但没有一个真正帮助我解决这个问题。 我有一个变量,我使用@Url.Action 将它传递给 Action 方法。 尽管变量 (studentList) 中有 3 个项目,但当我单击按钮时,它会向控制器发送一个空值。 任何帮助将不胜感激。

查看代码

 <tbody>
    @for (int i = 0; i < Model.Count(); i++)
    {
        var teacherId = Model[i].TeacherId;
        List<Student> studentList = db.Students.Where(s => s.TeacherId == teacherId).Select(s=>s).ToList();

        using (Html.BeginForm())
        {
            <tr>
                <input type="hidden" name="Index" value="@i" />
                <td>@Model[i].TeacherId</td>
                <td>@Model[i].FirstName</td>
                <td>@Model[i].LastName</td>
                <td><button type="button" class="btn btn-danger" onclick="popup('@Url.Action("TeachersSchedule", "Admin", studentList)','Schedule Details')">Details</button></td>
                </tr> } } </tbody>                  

Javascript代码

 <script> function popup(url, title) { var popupWindow = window.open(url, title, 'scrollbars=1,height=500,width=500, top=150, left=300'); } </script>

动作方法(控制器)

public ActionResult ScheduleDetails(List<Student> studentList)
    {
        return View(studentList);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM