[英]How to bind returned data to a Telerik ASP.Net Core grid after submitting a form with resulted data
I am creating a web app using ASP.Net Core MVC 3.1 With EF 3.1.我正在使用 ASP.Net Core MVC 3.1 和 EF 3.1 创建一个 Web 应用程序。 I add a web page to update student Telephone numbers as batches (Grade wise) using ASP.Net Core Telerik Grid.我添加了一个网页来使用 ASP.Net Core Telerik Grid 批量更新学生电话号码(Grade wise)。 There is a small form at the top of the Page and there are buttons and those allow to select the Grade that you want to update Telephone numbers of students.页面顶部有一个小表格,有按钮,这些按钮允许选择要更新学生电话号码的等级。 I need to show relevant students data in ASP.Net Core Telerik Grid below the Form control after clicking on a Grade button.单击成绩按钮后,我需要在表单控件下方的 ASP.Net Core Telerik Grid 中显示相关学生数据。 After Clicking on a Grade button, it selects and returned back relevant data but the grid does not show those data.单击成绩按钮后,它选择并返回相关数据,但网格不显示这些数据。
So My question is, how should I correct my coding, in order to view returned data?所以我的问题是,我应该如何更正我的编码,以查看返回的数据?
My coding are as follows我的编码如下
Index.cshtml索引.cshtml
@model School_MGT.Models.Students
<div class="container">
<div class="container">
<form asp-controller="AttendenceStudents" asp-action="Index">
<p align="center">
<input type="submit" name="btn" value="1A" />
<input type="submit" value="1B" name="btn" />
</p>
</form>
</div>
</div>
@(Html.Kendo().Grid<School_MGT.Models.Students>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Add_No);
columns.Bound(p => p.S_Name).Width(140);
columns.Bound(p => p.Tel_H).Width(140);
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Navigatable()
.Sortable()
.Scrollable()
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(20)
.ServerOperation(false)
.Model(model => model.Id(p => p.Add_No))
.Update("Update", "AttendenceStudents")
)
)
AttendenceStudentsController出勤学生控制器
namespace School_MGT.Controllers
{
public class AttendenceStudentsController : Controller
{
private readonly ConnectionString _context;
public AttendenceStudentsController(ConnectionString context)
{
_context = context;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Index(string btn)
{
var Students = from m in _context.Students select m;
switch (btn)
{
case "1A":
Students = Students.Where(x => x.Grade == "1" && x.Class == "A");
return View();
case "1B":
Students = Students.Where(x => x.Grade == "1" && x.Class == "B");
return View();
default:
return (View());
}
}
[HttpPost]
public IActionResult Update([Bind("RowID,Add_No,S_Name")] Students target)
{
Students entity = _context.Students.FirstOrDefault((r => r.Add_No == target.Add_No));
entity.Tel_H = target.Tel_H;
_context.SaveChanges();
return View();
}
}
}
Thank you all who viewed my question and try to answer.感谢所有查看我的问题并尝试回答的人。 I resolved my problem by modifying Index method and view.cshtml我通过修改 Index 方法和 view.cshtml 解决了我的问题
public async Task<IActionResult> Index(string btn)
{
var Students = from m in _context.Students select m;
switch (btn)
{
case "1A":
Students = Students.Where(x => x.Grade == "1" && x.Class == "A");
return View(await Students.ToListAsync());
case "1B":
Students = Students.Where(x => x.Grade == "1" && x.Class == "B");
return View(await Students.ToListAsync());
default:
return (View(await Students.ToListAsync()));
}
}
apply following changes to model and grid对模型和网格应用以下更改
@model IEnumerable<School_MGT.Models.Students>
@(Html.Kendo().Grid(Model)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.