I want to pass a parameter to an action link using a class. The action link look like this
@Html.ActionLink(pantalla.Descripcion, pantalla.Action, pantalla.Controlador, pantalla.Parametros)
The class is pantalla and has four attributes:
public class Pantalla
{
public int IdPantalla { get; set; }
public string Descripcion { get; set; }
public string Controlador { get; set; }
public string Action { get; set; }
public object Parametros { get; set; }
}
And I´m making a call to the action like this:
new Pantalla() { IdPantalla=11, Descripcion = "Consultas Abiertas Seguridad Social", Controlador = "ReportViewer", Action="EditViewerV2", Parametros=new{pReport="27f31533-e9f4-485f-acc3-6f420ea28014" } }
Every attribute goes to the action link except the last one, Parametros, and I guess that object might be the wrong type. Can someone help me on this Thanks a lot
The problem you're having really has to do with the type of property. The ActionLink method typically expects a routed value parameter of type object. However, when you define a Parametros property as an object in the Pantalla class, you may lose type information, resulting in links that are not serialized correctly when generated. To solve this problem, you can change the type of the Parametros property to RouteValueDictionary. The RouteValueDictionary is typically used to pass route-value parameters, and this class provides a convenient way to build and manage these key-value pairs,Here's a sample code you can use as a reference:
Action link:
After I clicked on the link:
Then I can successfully receive the parameters: