0
我有我的看法是這樣一個循環,產生student`s名得到錯誤404,同時傳遞一個數組通過Ajax控制器
<Table id="your_table">
<thead>
<tr>
<th>name</th>
<th>grade</th>
<th>remove</th>
</tr>
</thead>
<tbody>
@foreach (string item in Model)
{
<tr>
<td id="td_name" style="border-left: thin">@item</td>
<td><input type="text" id="[email protected]" onclick="" style="width: 40px;border-left: thin" /></td>
<td><input type="checkbox" id="[email protected]" value="@item" /></td>
</tr>
}
</tbody>
我用下面的腳本得到的文本列表每行的第一個單元格:
$('#btnDone')
.click(function() {
//get studentslist
function getFirstCellTextList(tableElement) {
if (tableElement instanceof jQuery) {
// Create an array
var textList = [];
// Iterate over each table row
tableElement.find('tbody tr').each(function() {
// Get the first cells's text and push it inside the array
var row = $(this);
if (row.children('td').length > 0) {
textList.push(row.children('td').eq(0).text());
}
});
return textList;
}
return null;
}
// Get the array
var lststudents = getFirstCellTextList($('#your_table'));
var result = [];
$(lststudents).each(function(index, item) {
result.push(item);
});
alert(result);
$.ajax('/TeacherPages/GetGrades/' + result).done(function() {
alert("done");
});
});
問題是。當我想發送創建的數組到控制器我得到錯誤404。這個數組有問題。因爲當我手動添加值到陣列的AJAX工作沒有任何問題
這是我的行動:
[AttributeRouting.Web.Mvc.GET("/TeacherPages/GetGrades/{result}")]
public PartialViewResult GetGrades(string[] result)
{
return PartialView();
}
不硬編碼的網址,不喜歡:'$阿賈克斯( '@ Url.Action( 「GetGrades」, 「TeacherPages」)'',並顯示你的行動是如何看起來像 –
你?如果你的方法有一個參數IEnumerable name,你的數組看起來像什麼? –
不能只是追加一個JavaScript數組到一個url - 你的url需要看起來像/ TeacherPages/GetGrades?name = ABC&name = DEF&name = etc它就像:name1.lastname1,name2.lastname2 –