首先,使用调试工具(如控制台)检查请求是否被正确发送,并确认字符串参数是否传递了。其次,检查控制器中的参数名称是否与AJAX请求中的参数名称一致。此外,还可以尝试使用JSON格式传递数据,并在控制器中使用合适的实体或对象来接收数据。以下是示例代码:
AJAX请求:
$.ajax({ type: 'POST', url: 'example/controller', data: { strValue: 'hello world' }, success: function(response) { console.log(response); } });
控制器:
[HttpPost] public IActionResult ControllerAction(string strValue) { // do something with strValue return Ok(); }