简体   繁体   English

将View的base64图像发送到ASP.NET控制器

[英]Send a base64 image from View to a ASP.NET Controller

I'm trying to send a base64 image from a View to a Controller. 我正在尝试将Base64图像从视图发送到控制器。

I have the base64 stored in an input and I get it like this (working fine): 我将base64存储在输入中,并且这样得到(工作正常):

var photoBase64Captured = $('#txtPhotoBase64Captured').val();

Then in my View , I call the Controller and wait for a response: 然后在View ,我调用Controller并等待响应:

$.get("@Url.Action("CheckFace", "User")", { base64: photoBase64Captured }, function (data) {

   var result = $.parseJSON(data);

   if (data != null) {

   }
});

When I try to call the Controller, I'm getting the following error in Chrome's console: 尝试致电Controller时,Chrome控制台出现以下错误:

Failed to load resource: net::ERR_SPDY_PROTOCOL_ERROR

This is the Controller : 这是Controller

public async Task<ActionResult> CheckFace(string base64)
{

}

Any ideas why this is happening? 任何想法为什么会这样? Is the base64 too long to send to the Controller ? base64是否太长而无法发送到Controller

If I send other values to the Controller it works fine, so it is not a problem of the method. 如果我将其他值发送到控制器,则可以正常工作,因此这不是方法的问题。

You need to use post for in this case. 在这种情况下,您需要使用post。 Image base64 to large for Get request. 将base64图像放大以获取请求。

$.post("@Url.Action("CheckFace", "User")", { base64: photoBase64Captured }, function (data) {

   var result = $.parseJSON(data);

   if (data != null) {

   }
});

[HttpPost]
public async Task<ActionResult> CheckFace(string base64)
{

}

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

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