在 ASP.NET MVC 中,如何只绑定 POST 变量,而不是 GET 变量

in ASP.NET MVC, How bind only POST variables, not GET variables

我确实遇到过用户想要创建实体的情况。 这是接收包含要绑定数据的 POST 变量的 Actions。但是 URL 中有一些同名的数据,例如 Action?Id=123

public ActionResult Create([Bind()] Entity entity) ... 

这是我的实体 POCO Class

public class Entity {

    public int Id {get;set;}
    public string SomeData {get;set;}

}

当数据绑定程序收到请求时,它会将 URL 中的 ID 绑定到实体。它不应该发生!,如何避免绑定来自 URL (GET) 的变量而只绑定来自 POST 数据的变量?

您可以使用属性过滤器从表单中明确获取数据:

public ActionResult Post([FromForm]int id)