Mr.Potkin Mr.Potkin - 3 months ago 13
C# Question

How to pass reference type into Url.Action

I'm trying to pass my model into

Url.Action
:

@Model FilterVm
@Url.Action("Index", "Home", new { filter = @Model })


but when my method is called, I got always null in parameter

public ActionResult Index (FilterVm filter)


How can I pass my model as a parameter in Url.Action?

Answer

You need to pass all fields of your model separately. For example, if your model contain 2 fields Name and Id Url.Action must be

@Url.Action("Index", "Home", new { Name = Model.Name, Id=Model.Id })

Also Model declaration in your view need to be in lower case

@model FilterVm
Comments