详细信息方法不带参数mvc

时间:2017-05-31 14:26:57

标签: c# .net model-view-controller

我使用MVC,c#和代码的其中一种方法,并没有使用id。我不知道为什么。你能帮帮我吗?:D

这是我的控制器方法

 public ActionResult Details(int? id)
    {

        AngajatRepository y = new AngajatRepository(conn);
        AngajatModel obAngajat = y.DetaliiAngajat(id);
        return View(obAngajat);
    }

这是我的存储库

 public AngajatModel DetaliiAngajat(int? id)
    {

        var obAngajat = new AngajatModel();
        oracleConnection.Open();
        string oString = "select angajat.marca, angajat.nume_ang, angajat.prenume_ang, angajat.data_nastere, angajat.data_ang, angajat.sex, angajat.cnp, angajat.salariu, departament.denum_dep, studii.tip_stud  from angajat inner join departament on angajat.departament_id_departam=departament.id_departam inner join studii on angajat.studii_id_stud=studii.id_stud and marca=:marca";
        using (var cmdg = new OracleCommand(oString, oracleConnection))
        {
            cmdg.Parameters.Add(new OracleParameter(":marca", id));
            using (OracleDataReader rd = cmdg.ExecuteReader())
            {
                while (rd.Read())
                {

                    obAngajat.Marca = Convert.ToInt32(rd["marca"]);
                    obAngajat.NumeAngajat = Convert.ToString(rd["nume_ang"]);
                    obAngajat.PrenumeAngajat = Convert.ToString(rd["prenume_ang"]);
                    obAngajat.DataNastere = Convert.ToDateTime(rd["data_nastere"]);
                    obAngajat.DataAngajarii = Convert.ToDateTime(rd["data_ang"]);
                    obAngajat.Sex = Convert.ToString(rd["sex"]);
                    obAngajat.CNP = Convert.ToString(rd["cnp"]);
                    obAngajat.Salariu = Convert.ToDouble(rd["salariu"]);
                    obAngajat.Departament = Convert.ToString(rd["denum_dep"]);
                    obAngajat.Studii = Convert.ToString(rd["tip_stud"]);
                }
                oracleConnection.Close();
            }
        }

        return (obAngajat);
    }

P.S。我没有错误或例外。它不会从控制器那里拿走我的身份。

0 个答案:

没有答案