Mr.Potkin Mr.Potkin - 1 year ago 73
C# Question

How to pass reference type into Url.Action

I'm trying to pass my model into


@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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download