我需要帮助。我是razor页面和asp.net核心的新手,我需要将我在HTML表格中的数据发送到我的帖子处理程序并保存它。
我在客户端上重新排序行,然后我需要在按钮单击时保存重新排序的行。
<form method="post">
<div>
<table id="example" class="table table-stripped border">
<thead>
<tr class="table-secondary">
<th>@Html.DisplayNameFor(m => m.DenniPlan.FirstOrDefault().CisloZakazky)</th>
<th>@Html.DisplayNameFor(m => m.DenniPlan.FirstOrDefault().CisloProduktu)</th>
<th>@Html.DisplayNameFor(m => m.DenniPlan.FirstOrDefault().Poradi)</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.DenniPlan)
{
<tr>
<td>@Html.DisplayFor(m => item.CisloZakazky)</td>
<td>@Html.DisplayFor(m => item.CisloProduktu)</td>
<td>@Html.DisplayFor(m => item.Poradi)</td>
</tr>
}
</tbody>
</table>
<button type="submit" class="btn btn-primary" >Časovat</button>
</div>
</form>
Index.cshtml.cs
private readonly DataContext _context;
public IEnumerable<DenniPlan2> DenniPlan { get; set; }
public IndexModel(DataContext context)
{
_context = context;
}
public async Task OnGet()
{
DenniPlan = await _context.DenniPlan2.Take(20).OrderBy(x => x.Poradi).ToListAsync();
}
要提交数据,您需要使用input
呈现数据。否则,您需要使用jquery来循环td
节点。但是,IMO,在不改变任何内容的情况下提交数据是不合理的。
public class IndexModel : PageModel
{
private readonly TestRazor.Data.ApplicationDbContext _context;
public IndexModel(TestRazor.Data.ApplicationDbContext context)
{
_context = context;
}
[BindProperty]
public IList<DenniPlan2> DenniPlan2 { get;set; }
public async Task OnGetAsync()
{
DenniPlan2 = await _context.DenniPlan2s.Take(3).ToListAsync();
}
public async Task<IActionResult> OnPostAsync()
{
var r = DenniPlan2;
return RedirectToPage("./Index");
}
}
<form method="post">
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.DenniPlan2[0].CisloZakazky)
</th>
<th>
@Html.DisplayNameFor(model => model.DenniPlan2[0].CisloProduktu)
</th>
<th>
@Html.DisplayNameFor(model => model.DenniPlan2[0].Poradi)
</th>
<th></th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.DenniPlan2.Count; i++)
{
<tr>
<td>
@Html.EditorFor(model => model.DenniPlan2[i].CisloZakazky)
</td>
<td>
@Html.EditorFor(model => model.DenniPlan2[i].CisloProduktu)
</td>
<td>
@Html.EditorFor(model => model.DenniPlan2[i].Poradi)
</td>
</tr>
}
</tbody>
</table>
<input type="submit" value="submit" />
</form>