即時通訊嘗試從datepicker獲取值並將這些值發佈到控制器。但是這些值在控制器端總是空的。我已閱讀關於此問題的其他線程,但無法得到任何幫助。POST日期時間與AJAX控制器asp.net核心
$(function GetFeed() {
$('#get_feed').click(function() {
var fromDate = $('#from_date').val();
var toDate = $('#to_date').val();
var price = $('#Price').val();
var _data = {
'fromDate': fromDate,
'toDate': toDate,
'price': price
}
$.ajax({
url: 'Home/GetFeedList',
type: 'POST',
data: _data,
contentType: "application/json",
dataType: 'json',
success: function (s) {
console.log('success' + s)
},
error: function (e) { console.log('something went wrong!', e, fromDate, toDate) }
});
});
});
而且繼承人控制器,所有參數都爲空:
public async Task<ActionResult> GetFeedList(string fromDate, string toDate, string price)
另外一個視圖模型
[Required(ErrorMessage = "Please insert start date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{dd-MM-yyyy}")]
public DateTime FromDate { get; set; }
[Required(ErrorMessage = "Please insert end date")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{dd-MM-yyyy}")]
public DateTime ToDate { get; set; }
變化是Ajax調用一個GET –