繁体   English   中英

等效于 ASP.NET Core 1.1 中的 BindPropertyAttribute

[英]Equivalent to BindPropertyAttribute in ASP.NET Core 1.1

由于托管服务提供商的限制,我被迫使用 ASP.NET Core 1.1。

我创建了一个 model class 并希望将 model 绑定到与 model 绑定到与 model 属性不同的命名值。

在 ASP.NET Core 2.0 以后,我将使用BindPropertyAttribute ,如下所示:

public class MyModel
{
    [BindProperty(Name="g-recaptcha-response")]
    public string GoogleReCaptchaResponse { get; set; }
}

但是, BindPropertyAttribute Core 1.1 不支持 BindPropertyAttribute。 有没有我可以使用的替代方案?

您可以使用ModelBinder属性:

[ModelBinder(Name = "g-recaptcha-response")]
public string GoogleReCaptchaResponse { get; set; }

在视图中,您应该将元素name设置为g-recaptcha-response以进行 model 绑定:

<input name="g-recaptcha-response" class="form-control" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM