如何通过asp.net中的actionlink发送数据? [英] How to send data through actionlink in asp.net?
问题描述
在我要制作的应用程序中,我的视图中有一个菜单,如下所示:
In the application that I am trying to make, I have a menu in my view as below:
<ul id="menu">
<li>@Html.ActionLink("Create Project", "Display", "CreateDisplay")</li>
<li>@Html.ActionLink("Open", "About", "Home")</li>
</ul>
其中CreateDisplay是控制器的名称,而Display是该控制器中将调用另一个视图的方法.
where CreateDisplay is the name of a controller and Display is a method in that controller which will call another view.
但是,我希望Display方法接受某些参数,例如此人的用户名.在当前视图中,我已获得用户名 @ViewData ["UserName"]
But, I want the Display method to accept certain parameters like username of the person.
In the current view, I have obtained the username as @ViewData["UserName"]
但是我无法使用ActionLink传递这些值.我尝试将参数传递为
But I am not able to pass these values using ActionLink. I tried passing the parameters as
<li>@Html.ActionLink("Create Project", "Display?UserName="+@ViewData["UserName"], "CreateDisplay")</li>
但收到异常.
请提出一些方法.
非常感谢您.
推荐答案
您需要使用接受参数的重载作为路由值.在此处查看重载方法 ActionLink()
You need to use the overload that accepts parameters for route values. See the overloaded method ActionLink()
here.
@Html.ActionLink(
"Click me!",
"Display",
"CreateDisplay",
new { UserName = "SetYourValHere" },
null);
这篇关于如何通过asp.net中的actionlink发送数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!