C# 当jQuery数据表更改行顺序时填充BindProperty集合
在MVC中填充控制器的BindProperty模型集合时,似乎我只能在索引正常时添加到返回数组中 以下是我在几个应用程序中使用的工作代码: 控制器代码:C# 当jQuery数据表更改行顺序时填充BindProperty集合,c#,jquery,html,model-view-controller,datatables,C#,Jquery,Html,Model View Controller,Datatables,在MVC中填充控制器的BindProperty模型集合时,似乎我只能在索引正常时添加到返回数组中 以下是我在几个应用程序中使用的工作代码: 控制器代码: <form asp-controller="Home" asp-action="EditFields" method="post" id="rateForm"> <table id="editTable" style="width: 100%; display: none" class="display" curso
<form asp-controller="Home" asp-action="EditFields" method="post" id="rateForm">
<table id="editTable" style="width: 100%; display: none" class="display" cursor="pointer">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
<th>Abbreviation</th>
<th>Active</th>
</tr>
</thead>
<tbody style="font-size: .8em">
@for (int i = 0; i < @Model.PayCodes.Count(); i++)
{
<tr>
<td>
<select class="hideFormBox pointerTransform" name="EditModel.PayCodes[@i].PayCodeType" id="EditModel.PayCodes[@i].PayCodeType">
@if (@Model.PayCodes[i].PayCodeType.Equals("Credit"))
{
<option selected value="Credit">Credit</option>
<option value="Debit">Debit</option>
}
else
{
<option value="Credit">Credit</option>
<option selected value="Debit">Debit</option>
}
</select>
</td>
<td>
<textarea class="hideFormBox" name="EditModel.PayCodes[@i].PayCodeDesc" id="EditModel.PayCodes[@i].PayCodeDesc" rows="1" required>@Model.PayCodes[i].PayCodeDesc</textarea>
</td>
...
<input type="hidden" name="EditModel.PayCodes[@i].PayCodeKey" id="EditModel.PayCodes[@i].PayCodeKey" value="@Model.PayCodes[i].PayCodeKey" />
</tr>
}
</tbody>
</table>
<input type="hidden" name="EditModel.EditRateType" id="EditModel.EditRateType" value="@EditRateType.PayCode" />
</form>
@section ChartScript
{
<script type="text/javascript">
$(document).ready(function() {
$('#editTable').show();
$('#editTable').DataTable({
searching: false,
dom: 'Bfrtip',
buttons: [],
}
);
});
</script>
}
If I had three objects from db with index 0, 1, 2 -
If the user sorts by reverse order: 2, 1, 0 = 1 item (index 0)
If the user goes to the second page: 10, 11, 12.. = 0 items (no 0)
If the user sorts filters something: 0, 10 = 1 item
填充的绑定属性:
[BindProperty]
public EditRatesModel EditModel { get; set; }
上述模式:
public class EditRatesModel
{
public EditRateType EditRateType { get; set; }
public List<PayCode> PayCodes { get; set; } <--This works as array or List
...
我可以关闭排序,但这并不能解决分页问题。
要修复分页,我必须用ajax加载mvc,或者一次加载一个新视图,比如10个
我的问题:
必须有更好的方法来做到这一点,而不必在控制器中使用@HTML编辑器或分页?
是否有一个js或jquery解决方案可以让我无序地填充愚蠢的硬编码对象
最后一个结果是,我想我可以用AJAX输入AJAX输出AJAX?但是,考虑到上面的编辑方法,我不确定如何做后者
我为这个冗长且可能非常规的问题道歉。我的前端经验有限
If I had three objects from db with index 0, 1, 2 -
If the user sorts by reverse order: 2, 1, 0 = 1 item (index 0)
If the user goes to the second page: 10, 11, 12.. = 0 items (no 0)
If the user sorts filters something: 0, 10 = 1 item