我是 asp.net mvc 的新手,所以我对 kendo mvc 网格有一些问题。这是我的模型:
public class LessonsDep
{
public int LesId { get; set; }
public int Activated { get; set; }
public string TaskTable { get; set; }
}
public class LessonsBusinessLayer
{
public void changeLessons(LessonsDep lessons){
string connectionString = ConfigurationManager.ConnectionStrings["nisa1415"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("dep.edidBiology",con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramId = new SqlParameter();
paramId.ParameterName = "@LesId";
paramId.Value = LessonNameClass.stcLesId;
cmd.Parameters.Add(paramId);
SqlParameter paramActivated = new SqlParameter();
paramActivated.ParameterName = "@Activated";
paramActivated.Value = lessons.Activated;
cmd.Parameters.Add(paramActivated);
SqlParameter paramTaskTable = new SqlParameter();
paramTaskTable.ParameterName = "@TaskTable";
paramTaskTable.Value = lessons.TaskTable;
cmd.Parameters.Add(paramTaskTable);
con.Open();
cmd.ExecuteNonQuery();
}
}
}
///------------------------------------------------ - - - - - - - - -/// 风景:
@model IEnumerable<BusinessLayer.LessonsDep>
<div id="clientsDb">
@(Html.Kendo().Grid(Model)
.Name("grid")
.Scrollable()
.Columns(columns =>
{
columns.Bound(c => c.LesId).Width(140);
columns.Bound(c => c.Activated).Width(50);
columns.Bound(c => c.TaskTable).Width(300);
})
.HtmlAttributes(new { style = "height: 500px;" })
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.ToolBar(toolbar =>
{
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(c => c.LesId))
.Read("Editing_Read", "LessonController")
.Update("Editing_Update", "Lesson")
)
)
/ -------------------------------------------------- ------ / 和控制器:
public ActionResult Index2()
{
LessonsBusinessLayer lessonsBusinessLayer = new LessonsBusinessLayer();
List<LessonsDep> lessons = lessonsBusinessLayer.LessonsDeps.ToList();
string myString = LessonNameClass.LessonsName;
return View(lessons);
}
在这里我想添加应该更新数据的方法:
public ActionResult Editing_Update()
{
//.......Can I call ChangeLesson() Method from LessonsBusinessLayer?
//if answer is: yes then How i should call this method?
return View();
}