0
hello! I am doing a crud project on Asp net mvc and my code presents the following error:
Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot Convert from 'int' to 'CRUD.Models.Times'
This error occurs when I pass the id parameter into the Try.
public ActionResult ExcluirTime(int id)
{
try
{
_repositorio = new TimeRepositorio();
if(_repositorio.ExcluirTime(id)) //o erro se dá no id
{
ViewBag.Message("Time excluído com sucesso!");
}
return RedirectToAction("MostrarTimes");
}
catch (Exception)
{
return View("MostrarTimes");
}
}
Class Excluirtime
public bool ExcluirTime(Times objTimes)
{
int i;
Connection();
using(SqlCommand consulta = new SqlCommand("ExcluirTime", _con))
{
consulta.CommandType = CommandType.StoredProcedure;
_con.Open();
consulta.Parameters.AddWithValue("@time", objTimes.cd_time);
i = consulta.ExecuteNonQuery();
};
_con.Close();
if(i >= 1)
{
return true;
}
return false;
}
Also put the function
ExcluirTime
classTimeRepositorio
in your question so we can help you– Natan Fernandes
ready, put on
– user215274
The function expects an object of the type
Times
and not an id, you need to search among all teams the one that has the desired id and only then pass this team as a function parameter– Natan Fernandes
now it’s gone! thank you
– user215274