ASP.NET Core中的FromUriAttribute替换-专门用于参数别名吗? [英] FromUriAttribute replacement in ASP.NET Core - specifically for parameter aliasing?

查看:379
本文介绍了ASP.NET Core中的FromUriAttribute替换-专门用于参数别名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下API的MVC控制器:

I have an MVC Controller with the following API:

public CustomObject Get([FromUri] float lat, [FromUri(Name="long")] float longitude, string userKey = null)

这可行,但是由于不赞成FromUri,因此需要兼容垫片.

This works, but requires the compatibility shim since FromUri is deprecated.

如何使用适当的ASP.NET Core API复制经度参数的别名"行为?

How do I replicate the "aliasing" behavior of the longitude parameter with proper ASP.NET Core API?

推荐答案

使用绑定属性"作为替代解决方案

Use the Bind Attribute as an alternative solution

public CustomObject Get(float lat, [Bind(Prefix = "long")]float longitude, string userKey = null)

这篇关于ASP.NET Core中的FromUriAttribute替换-专门用于参数别名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆