我是 MVC 的新手,我正在尝试在我的演示应用程序中使用 WebGird 控件,我执行以下任务:-
家庭控制器
public ActionResult Index()
{
List<Student> listStudent = new List<Student>();
listStudent.Add(new Student { Id = 1000, Name = "Sumit Kesarwani", IsActive = true });
listStudent.Add(new Student { Id = 1001, Name = "Arun Singh", IsActive = true });
listStudent.Add(new Student { Id = 1002, Name = "Vijay Shukla", IsActive = false });
listStudent.Add(new Student { Id = 1003, Name = "Pwan Shukla", IsActive = true });
var data = listStudent;
return View(data);
}
学生.cs
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
}
索引.cshtml
@model IEnumerable<MvcWebGrid.Models.Student>
@{
ViewBag.Title = "Home Page";
WebGrid webGrid = new WebGrid(Model);
}
@webGrid.GetHtml(columns: new[]{
webGrid.Column("Id"),
webGrid.Column("Name"),
webGrid.Column("IsActive", header: "", format:@<text><input name="isActive"
type="checkbox" @item.IsActive == "true" ? "checked" : ""/></text>)
})
上面WebGrid
将显示readonly
模式下的所有数据,但我需要这些数据以可编辑模式显示,例如 Id 将显示在隐藏字段中,名称将显示在Textbox
,当数据加载checkbox
将检查其属性是否具有真实值时,checkbox
将检查属性是否具有假值然后checkbox
会uncheck
。
请请请帮帮我!
任何帮助将不胜感激!