[英]How to pass a parameter value from view to controller?
I would like to pass a parameter value from view to my controller but it is not working. 我想将参数值从视图传递到控制器,但无法正常工作。 Here is the method which I am using:
这是我正在使用的方法:
@Html.ActionLink("English","ResourseLang","mvcResourseController", new { lang = "value" })
In the controller the lang
value is null
在控制器中
lang
值为null
public ActionResult ResourseLang(String lang) {
String ab = lang;
return view("Index");
}
You will get like below: 您将得到如下所示:
@Html.ActionLink("English","ResourseLang", new { @lang = "value" })
At controller side code will be same as you wrote. 在控制器端,代码将与您编写的相同。
public ActionResult ResourseLang(String lang) {
String ab = lang;
return view("Index");
}
Ref : 参考:
https://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/ajax-actionlink-and-html-actionlink-in-mvc/ https://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/ajax-actionlink-and-html-actionlink-in-mvc/
You can test MVC
code online here: 您可以在此处在线测试
MVC
代码:
https://dotnetfiddle.net/CsMvc https://dotnetfiddle.net/CsMvc
You are using a wrong Html.ActionLink
overload and missing html attributes. 您使用了错误的
Html.ActionLink
重载和缺少html属性。 Pass null
if you are not adding any html attributes. 如果不添加任何html属性,则传递
null
。 So you should use it like below: 因此,您应该像下面这样使用它:
Razor: 剃刀:
@Html.ActionLink(
"English", //Action Link Text
"ResourseLang", //Action Name
"mvcResourseController", //Controller Name
new { lang = "value" }, //Route Values
null //Html Attributes
)
Controller: 控制器:
public ActionResult ResourseLang(string lang) {
string ab = lang;
return view("Index");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.