如何将 c# class 文件的响应发送到 MVC 控制器

How can I send response from c# class file to MVC Controller

如果我的条件失败 rdr.HasRows == true,我该如何响应我的控制器失败

public Employee DeleteEmpById(int key)
{
    try
    {
        SqlCommand cmd = new SqlCommand("Sp_GetEmployeeById", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@EmpId", key);
        SqlDataReader rdr = cmd.ExecuteReader();
        if (rdr.HasRows == true)
        {
        }
        else
        // Here what I mention when rdr.HasRows false
    }

控制器

public ActionResult DeleteById(int id)
{
    var x = ObjRepo.DeleteEmpById(id);
    return View(x);
}

边读边用

 Bool HasData =False ;
 SqlDataReader rdr = cmd.ExecuteReader();

while (rdr.Read())
 {
    // If there is A row  sqlDataReader Will read 
    HasData  =true ;
    break; // you only have to check one time ,  performance improve


 }



return HasData