如何在ASP.NET MVC中使用Html.Action()将参数传递给Action? [英] How can I pass parameters to an Action using Html.Action() in ASP.NET MVC?

查看:495
本文介绍了如何在ASP.NET MVC中使用Html.Action()将参数传递给Action?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Html.Action("ActionName", "ControllerName")来跨控制器调用子操作,而无需将视图放在Views \ Shared中.这对于显示会话或cookie信息之类的东西非常有用.

I've been using Html.Action("ActionName", "ControllerName") to invoke child actions across controllers without needing to have the view in Views\Shared. This has been working great for displaying things like session or cookie information.

我不仅要访问cookie,还希望将其他参数传递给Html.Action("ActionName", "ControllerName"),以便该操作可以根据传递给原始视图的数据执行不同的代码.

Instead of just accessing cookies, I would like to pass additional parameters to Html.Action("ActionName", "ControllerName") so the action can execute different code based on the the data passed to the original view.

我应该使用其他方法将参数传递给其他控制器中的子动作吗?一个人怎么做到的?

Should I be using a different method to pass parameters to a child action in a different controller? How would one accomplish this?

推荐答案

您可以像这样在RouteValues属性中指定其他数据.

You could specify additional data in the RouteValues property like this.

Html.Action("ActionName","Controller", new { id = 1 })

这篇关于如何在ASP.NET MVC中使用Html.Action()将参数传递给Action?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆