Wie lese ich RAW JSON -Anforderungskörper in ASP.NET MVC bei Verwendung von Application/JSON?
Posted: 20 Mar 2025, 22:26
beim Senden von Daten über AJAX mithilfe von ContentType: application/JSON sind die Daten in Request nicht verfügbar. FORMENE In meinem ASP.NET-MVC-Controller. Request.form ["input1"].
Controller -Teil
Code: Select all
// reading form data
var form = $("form")[0];
var formData = new FormData(form);
var object = {};
formData.forEach(function(value, key){
object[key] = value;
});
var data = JSON.stringify(object);
// ajax part
// POST application/json; charset=utf-8
$.ajax({
type: "POST",
url: "@Url.Action("FormSubmit","Home")",
data: data,
dataType: "json",
async: true,
contentType: "application/json",
processData: true,
success: function(result) { },
error: function(result) { }
});
Code: Select all
[HttpPost]
public ActionResult FormSubmit(string input1, string input2)
{
var httpContext= HttpContext;
var response = Response;
var request = Request;
throw new NotImplementedException();
}