@Model返回空并在控制器中生成错误

时间:2019-07-15 22:11:30

标签: asp.net-mvc visual-studio oracle11g

我正在做一个辅助系统,我正在传递位于Vista前端的Model列表。该列表将在参数中接收驱动程序“ TakeAsistance”,然后它将在执行系统时立即经历来自控制器的另一个foreach,因为该列表显示为空。结果是“ System.NullReferenceException”错误,换句话说就是NULL。我想知道如何避免该空值。

查看

@model IEnumerable<wsCharlas.Models.ClsInteresado>

@{
    /**/

    ViewBag.Title = "List Members";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>List Members:</h2>
<h6>Here you can place all the respective data of the chat you want to create.</h6>

<hr />

@using (Html.BeginForm())
{
    <h6>Search Interested: </h6>
    <input type="text" placeholder="Enter the name of an interested" class="form-control" />
    <br />
    <input type="submit" class="form-control" value="Search" />
    <br />
}

<hr />

<div>
    @Html.ActionLink("Save assistance", "TomarAsistencia", null, new { @class = "btn btn-primary" }, new { listaInteresados = Model })
    @Html.ActionLink("Return", "MostraCharlas", null, new { @class = "btn btn-primary" })
</div>

<hr />

<table class="table table-bordered table-striped">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.dni_Inter)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.apePat_Inter)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.apeMat_Inter)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.nombres_Inter)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.asistencia_Inter)
        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.dni_Inter)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.apePat_Inter)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.apeMat_Inter)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.nombres_Inter)
            </td>
            <td class="td-asistencia">
                @Html.CheckBoxFor(modelItem => item.asistencia_Inter)
            </td>
        </tr>
    }

</table>

<div>
    @Html.ActionLink("Save assistance", "TomarAsistencia", null, new { @class = "btn btn-primary" }, new { listaInteresados = Model})
    @Html.ActionLink("Return", "MostraCharlas", null, new { @class = "btn btn-primary"})
</div>

<style>

    .container {
        max-width: 1250px;
    }

    .td-asistencia {
        text-align: center;
    }
</style>

控制器

//REGISTER ASSISTANCE
    public ActionResult TomarAsistencia(IEnumerable<ClsInteresado>listaInteresados)
    {

        foreach (var item in listaInteresados)
        {
            ClsConexion con = new ClsConexion();
            var Cnx = con.Conexion();

            OracleCommand cmd = new OracleCommand("SIMEXA_SP_TOMAR_ASISTENCIA", Cnx);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new OracleParameter("param_id_asis", OracleDbType.Varchar2)).Value = item.ID_Inter;
            cmd.Parameters.Add(new OracleParameter("param_dni_asis", OracleDbType.Varchar2)).Value = item.dni_Inter;
            cmd.Parameters.Add(new OracleParameter("param_desc_asis", OracleDbType.Varchar2)).Value = item.asistencia_Inter;
            Cnx.Open();

            OracleTransaction tx = Cnx.BeginTransaction();
            cmd.ExecuteNonQuery();
            tx.Commit();

            Cnx.Close();
            cmd.Dispose();
            Cnx.Dispose();
        }

        return RedirectToAction("MostraCharlas");

    }

0 个答案:

没有答案