Ajax ONENET,Net Core 2.1 Ajax Post to Controller

I have been pulling my hair over this one for some time now and just don't see what I'm doing wrong.

I have a series of fields in a SWAL dialog I want to post to my controller but for the life of me it just won't, doesn't even call the Post method. Error received is just the 400 error code.

var issue = JSON.stringify(this.swalForm);

$.ajax({

type: "POST",

url: "../api/Issues",

contentType: "application/json; charset=utf-8",

beforeSend: function (xhr) {

xhr.setRequestHeader("RequestVerificationToken",

$('input:hidden[name="__RequestVerificationToken"]').val());

},

dataType: "json",

data: issue,

error: function (xhr) {

alert('Error: ' + xhr.statusText);

},

success: function (msg) {

console.log(msg.result);

}

});

That's my AJAX call

[HttpPost]

public async Task PostIssue([FromBody] Issue issue)

{

if (!ModelState.IsValid)

{

return BadRequest(ModelState);

}

_context.Issue.Add(issue);

await _context.SaveChangesAsync();

return CreatedAtAction("GetIssue", new { id = issue.Id }, issue);

}

This is the Post Method in my controller

public partial class Issue

{

public Issue()

{

Document = new HashSet();

IssueMember = new HashSet();

}

public int Id { get; set; }

public string Title { get; set; }

public string Description { get; set; }

public DateTime? DueDate { get; set; }

public int CategoryId { get; set; }

public int StatusId { get; set; }

public int? PriorityId { get; set; }

public int ProjectId { get; set; }

public string Location { get; set; }

public int TeamId { get; set; }

public DateTime CreatedDate { get; set; }

public int CreatedById { get; set; }

public DateTime? ModifiedDate { get; set; }

public int? ModifiedById { get; set; }

public bool Active { get; set; }

public Category Category { get; set; }

public User CreatedBy { get; set; }

public User ModifiedBy { get; set; }

public Priority Priority { get; set; }

public Project Project { get; set; }

public Status Status { get; set; }

public Team Team { get; set; }

public ICollection Document { get; set; }

public ICollection IssueMember { get; set; }

}

What the Model looks like

{"Title":"Ajax Issue","Description":"Made with ajax","DueDate":"2018-08-21","CategoryId":"3","StatusId":"2","PriorityId":"3","ProjectId":"1","Location":"Home","TeamId":"1","CreatedDate":"2018-08-21","CreatedById":"1","ModifiedDate":"2018-08-21","ModifiedById":"1","Active":"Active"}

And finally what the payload looks like on Post

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值