0
我嘗試使用Ajax Call($ .ajax)將ASP.NET MVC RAZOR中的數據列表發送到ActionResult(在控制器上),並且在控制器(服務器端)上,ActionResult的參數爲NULL。Ajax數據傳輸器
//ajax call
$.ajax({
url: "@Url.Content("~/DayPartConfig/Index")",
type: "POST",
cache: false,
data: myItems,
success: function(data){
alert('success');
},
error: function() {
alert('Error updating the time interval.');
},
complete: function(){
//hide preloader
alert('preloader');
}
});
名稱和禮儀的結構從myItems是相同時段:
public partial class DayPart
{
public DayPart()
{
this.EventGoalDayParts = new HashSet<EventGoalDayPart>();
}
public int DayPartID { get; set; }
public int Position { get; set; }
public string Name { get; set; }
public bool IsEnable { get; set; }
public Nullable<System.TimeSpan> Start { get; set; }
public Nullable<System.TimeSpan> End { get; set; }
public virtual ICollection<EventGoalDayPart> EventGoalDayParts { get; set; }
}
,並從JavaScript:
for (i = 1 ; i<= @Model.Count()-1;i++)
{
CreatedItem = {'DayPartID': i,
'Position': i,
'Name': $("#Name_"+i).val(),
'IsEnable': $("#IsEnable_"+i).val(),
'Start': $('#timepicker-'+ i).val()
};
myItems[i] = CreatedItem;
//alert(myItems[i]);
}
而現在,爲什麼從控制器的型號是空? ??
[HttpPost]
public ActionResult Index(List<DayPart> model)
{
...
}