繁体   English   中英

如何将引用类型传递给Url.Action

[英]How to pass reference type into Url.Action

我正在尝试将我的模型传递给Url.Action

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

但是当我的方法被调用时,参数总是为null

public ActionResult Index (FilterVm filter)

如何在Url.Action中将模型作为参数传递?

您需要分别传递模型的所有字段。 例如,如果您的模型包含2个字段,则Name和Id Url.Action必须为

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

另外,您认为模型声明必须小写

@model FilterVm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM