Map ASP.NET MVC action parameter name to another name

前端 未结 1 532
陌清茗
陌清茗 2021-01-14 18:08

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=lo         


        
1条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-14 18:23

    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;
    }
    

    0 讨论(0)
提交回复
热议问题