I cant receive ActionLink Parameters in controller?

71 views Asked by At

Im working in a C# MVC .Net web project, and I used an ActionLink with a parameter, but I cant read it into the Controller.

Actionlink:

@model IEnumerable<FINAL.Models.Medico>

@foreach (var item in Model) 
{
    @Html.ActionLink("Eliminar", "DeleteMedico", new { id = item.NOMBRE.ToString() })
}

And heres how im trying to read it:

public ActionResult DeleteMedico(String elmedico) 
{
    //This WRITE is returning null. :(
    System.Diagnostics.Debug.WriteLine("ELMEDICO:" + elmedico);
    return View();    
}

Im pretty new in MVC .NET development so I need your help.

Thanks.

1

There are 1 answers

3
David L On BEST ANSWER

Your parameter is improperly named based on your controller's expected arguments.

Either rename the parameter being passed:

@Html.ActionLink("Eliminar", "DeleteMedico", new { elmedico = item.NOMBRE.ToString() })

Or rename the controller's argument to id:

public ActionResult DeleteMedico(String id) 
{
    System.Diagnostics.Debug.WriteLine("ELMEDICO:" + id);
    return View();
}