gpt4 book ai didi

asp.net-mvc - 如何在 ASP.NET MVC 中捕获 g-recaptcha-response?

转载 作者:行者123 更新时间:2023-12-02 17:30:26 24 4
gpt4 key购买 nike

我正在尝试将带有 ReCaptcha 的表单发布到 mvc Controller 。

<div class="g-recaptcha" data-sitekey="some_site_key"></div>

从 Chrome 中的网络监视器我可以看到发射的数据

enter image description here

但是我在 Controller 中接收这些数据时遇到了困难,我尝试使用 View 模型[Required(AllowEmptyStrings = false, ErrorMessage = "Captcha required")]
公共(public)字符串 googleCaptcha { 获取;放; }

但我无法将变量 googleCaptcha 映射到 g-recaptcha-response,是否有数据属性允许我这样做?

我显然无法命名变量g-recaptcha-response,因为 c# 不允许这些命名约定

最佳答案

有几个创建自定义绑定(bind)属性的示例,该属性允许您指定别名,如果您要为多个属性添加别名,我将采用这种方式: https://ole.michelsen.dk/blog/bind-a-model-property-to-a-different-named-query-string-field.html

但是,对于一次性方法,我只需读取提交的值并手动设置我的属性:

[HttpPost]
public ActionResult SubmitAction()
{
var recaptchaResponse = Request["g-recaptcha-response"];

var myCaptcha = new MyCaptcha();
myCaptcha.googleCaptcha = recaptchaResponse

//..
}

关于asp.net-mvc - 如何在 ASP.NET MVC 中捕获 g-recaptcha-response?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38861301/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com