How do I remap an MVC action parameter to another parameter name?

前端 未结 2 961
暗喜
暗喜 2021-02-01 14:08

I have to implement an MVC action that is invoked like this:

http://address/Controller/MyAction?resName=name

and it\'s called by a third party

2条回答
  •  不思量自难忘°
    2021-02-01 14:49

    Another option is to use the ActionParameterAlias library. The nice thing about it is that both names for a given parameter will work.

    e.g.

    using ActionParameterAlias;
    //...
    
        [ParameterAlias("resourceName", "resName", Order = 1)]
        ActionResult MyAction( String resourceName )
    

    Then calls to the controller like http://address/Controller/MyAction?resourceName=name and http://address/Controller/MyAction?resName=name will both work just fine.

提交回复
热议问题