[英]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.