2 回答
TA贡献1809条经验 获得超8个赞
您已[FromBody]为控制器方法参数注释或使用原始类型。
[HttpPost]
public JsonResult IndexTCS([FromBody] UsuarioViewModel usuarioView)
{
bool successToStoreData = SomeMethod(usuarioView);
if (successToStoreData)
{
return Ok(usuarioView); // indicates success
}
else
{
return BadRequest("Your error message");
}
}
示例为[HttpGet].
[HttpGet]
public JsonResult IndexTCS(string someVal, string someOtherVal)
{
...
UsuarioViewModel model = new UsuarioViewModel();
model.someVal = someVal;
model.someOtherVal = someOtherVal;
...
}
TA贡献1821条经验 获得超6个赞
您应该将ajaxsuccess:函数参数从function (data, status)to更改,function (data)返回的Json结果将存储在data
你的代码应该是这样的:
function ValidarExisteContactoPago() {
var Nombre;
var IdUsuario;
if ($("#Nombre").val() !== null || $("#IdUsuario").val() !== null) {
IdUsuario = $("#IdUsuario").val();
Nombre = $("#Nombre").val();
$.ajax({
type: "GET",
url: "/Pago/IndexTCS",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {
IdUsuario: $("#IdUsuario").val(),
Nombre: $("#Nombre").val()
},
async: false,
success: function (data) {
// alert("Data: " + data + "\nStatus: " + status);
if (data === "success") {
window.location.href = "/Pago/IndexTC";
} else {
console.log('Data received: ');
}
},
error: function (data) {
console.log('Data received: ');
}
});
} else {
console.log('Data received: ');
}
}
添加回答
举报