将ASP.NET MVC操作参数名称映射到另一个名称 [英] Map ASP.NET MVC action parameter name to another name
本文介绍了将ASP.NET MVC操作参数名称映射到另一个名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将动作的参数映射到其他名称吗?
Can I map an action's parameter to a different name?
我想使用保留字作为操作的参数,例如:
I want to use reserved words as parameters for an action, such as:
search?q=someQuery&in=location&for=x
因此,"in"和"for"不能用作方法的参数名称. 有内置功能吗?还是应该创建模型绑定程序?
So "in" and "for" can't be used as parameter names of the method. Is there a built in feature for that or should I create a model binder?
谢谢.
推荐答案
您可以使用'@'表示法对名称进行逐字解释,而不是c#中的保留字.
You can use the '@' notation to make the name be interpreted literally rather than a reserved word in c#.
public ActionResult Test(string @for)
{
var something = @for;
}
这篇关于将ASP.NET MVC操作参数名称映射到另一个名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文