I have a ap.net mvc4 page in which there is one form and two grids but my problem is that grids are firing the wrong methods and i have no clue what is wrong can someone please help me out i had the similar problem in the past i created a page again with the same code anf it worked but now i am not able to solve this problem. My update method is calling the update method and other methods are firing wrong methods as well please help me out
<kendo:grid>
<%: Html.Kendo().Grid<SSTS.Models.StudentsViewModel>()
.Name("grid")
.Columns(columns =>
{
// columns.Bound(student => student.CustomerName);
columns.Bound(student => student.SchoolYear).Width(160);
columns.Bound(student => student.YearStart).Width(50);
columns.Bound(student => student.YearEnd).Width(50);
columns.Command(commands =>
{
commands.Edit(); // The "edit" command will edit and update data items
commands.Destroy(); // The "destroy" command removes data items
}).Title("Commands").Width(50);
})
.ToolBar(toolbar => toolbar.Create()) // The "create" command adds new data items
.Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode
.DataSource(dataSource =>
dataSource.Ajax()
.Model(model =>
{
model.Id(student => student.StudentNumber); // Specify the property which is the unique identifier of the model
// model.Field(student => student.StudentNumber).Editable(false); // Make the studentID property not editable
model.Field(p => p.StudentNumbers).DefaultValue(
ViewData["defaultCategory"] as SSTS.Models.StudentNumbersViewModel);
})
.Create(create => create.Action("students_Create", "Student")) // Action invoked when the user saves a new data item
.Read(read => read.Action("students_Read", "Student")) // Action invoked when the grid needs data
.Update(update => update.Action("students_Update", "Student")) // Action invoked when the user saves an updated data item
.Destroy(destroy => destroy.Action("students_Destroy", "Student")) // Action invoked when the user removes a data item
)
.Pageable()
%>
<%: Html.Kendo().Grid<SSTS.Models.StudentsViewModel>()
.Name("grid2")
.Columns(columns =>
{
// columns.Bound(student => student.CustomerName);
columns.Bound(student => student.BoardingPoint);//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
columns.Bound(student => student.StudentNumber).ClientTemplate(
"<a href='" +
Url.Action("ViewStudent", "Home") +
"/#= StudentNumber #'" +
">#= StudentNumber #</a>"
); ;
columns.Bound(student => student.Description).Width(250);
columns.Bound(student => student.NumberofSections).Width(250);
columns.Bound(student => student.ContactNumber).Width(250);
columns.Command(commands =>
{
commands.Edit(); // The "edit" command will edit and update data items
commands.Destroy(); // The "destroy" command removes data items
}).Title("Commands").Width(200);
})
.ToolBar(toolbar => toolbar.Create()) // The "create" command adds new data items
.Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode
.DataSource(dataSource =>
dataSource.Ajax()
.Model(model =>
{
model.Id(student => student.StudentNumber); // Specify the property which is the unique identifier of the model
// model.Field(student => student.StudentNumber).Editable(false); // Make the studentID property not editable
// model.Field(p => p.CustomerNames).DefaultValue(
// ViewData["defaultCategory"] as KendoGridAjaxEditing2.Models.CustomerNamesViewModel);
})
.Create(create => create.Action("BoardingPoints_Create", "Student")) // Action invoked when the user saves a new data item
.Read(read => read.Action("BoardingPoints_Read", "Student")) // Action invoked when the grid needs data
.Update(update => update.Action("BoardingPoints_Update", "Student")) // Action invoked when the user saves an updated data item
.Destroy(destroy => destroy.Action("BoardingPoints_Destroy", "Student")) // Action invoked when the user removes a data item
)
.Pageable()
%>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult students_Create([DataSourceRequest]DataSourceRequest request, StudentsViewModel students)
{
var results = new List<StudentsViewModel>();
if (students != null )//&& ModelState.IsValid)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.InsertSchoolYear(students, _studNum);
results.Add(students);
}
return Json(results.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult students_Update([DataSourceRequest]DataSourceRequest request, StudentsViewModel students)
{
if (students != null && ModelState.IsValid)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.UpdateSchoolYear(students);
UpdateModel(students);
}
return Json(new[] { students }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult students_Destroy([DataSourceRequest]DataSourceRequest request, StudentsViewModel product)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.DeleteSchoolYear(product);
return Json(new[] { product }.ToDataSourceResult(request, ModelState));
}
public ActionResult BoardingPoints_Read([DataSourceRequest] DataSourceRequest request)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
return Json(StudentRepository.GetSBoardingPoint(_studNum).ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult BoardingPoints_Create([DataSourceRequest]DataSourceRequest request, StudentsViewModel students)
{
var results = new List<StudentsViewModel>();
if (students != null )
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.InsertBoardingPoint(students, _studNum);
results.Add(students);
}
return Json(results.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult BoardingPoints_Update([DataSourceRequest]DataSourceRequest request, StudentsViewModel students)
{
if (students != null )
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.UpdateBoardingPoint(students);
UpdateModel(students);
}
return Json(new[] { students }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult BoardingPoints_Destroy([DataSourceRequest]DataSourceRequest request, StudentsViewModel product)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.DeleteBoardingPoint(product);
return Json(new[] { product }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
<kendo:grid>
<%: Html.Kendo().Grid<SSTS.Models.StudentsViewModel>()
.Name("grid")
.Columns(columns =>
{
// columns.Bound(student => student.CustomerName);
columns.Bound(student => student.SchoolYear).Width(160);
columns.Bound(student => student.YearStart).Width(50);
columns.Bound(student => student.YearEnd).Width(50);
columns.Command(commands =>
{
commands.Edit(); // The "edit" command will edit and update data items
commands.Destroy(); // The "destroy" command removes data items
}).Title("Commands").Width(50);
})
.ToolBar(toolbar => toolbar.Create()) // The "create" command adds new data items
.Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode
.DataSource(dataSource =>
dataSource.Ajax()
.Model(model =>
{
model.Id(student => student.StudentNumber); // Specify the property which is the unique identifier of the model
// model.Field(student => student.StudentNumber).Editable(false); // Make the studentID property not editable
model.Field(p => p.StudentNumbers).DefaultValue(
ViewData["defaultCategory"] as SSTS.Models.StudentNumbersViewModel);
})
.Create(create => create.Action("students_Create", "Student")) // Action invoked when the user saves a new data item
.Read(read => read.Action("students_Read", "Student")) // Action invoked when the grid needs data
.Update(update => update.Action("students_Update", "Student")) // Action invoked when the user saves an updated data item
.Destroy(destroy => destroy.Action("students_Destroy", "Student")) // Action invoked when the user removes a data item
)
.Pageable()
%>
<%: Html.Kendo().Grid<SSTS.Models.StudentsViewModel>()
.Name("grid2")
.Columns(columns =>
{
// columns.Bound(student => student.CustomerName);
columns.Bound(student => student.BoardingPoint);//.ClientTemplate("#=CustomerNames.CustomerName#").Width(160);
columns.Bound(student => student.StudentNumber).ClientTemplate(
"<a href='" +
Url.Action("ViewStudent", "Home") +
"/#= StudentNumber #'" +
">#= StudentNumber #</a>"
); ;
columns.Bound(student => student.Description).Width(250);
columns.Bound(student => student.NumberofSections).Width(250);
columns.Bound(student => student.ContactNumber).Width(250);
columns.Command(commands =>
{
commands.Edit(); // The "edit" command will edit and update data items
commands.Destroy(); // The "destroy" command removes data items
}).Title("Commands").Width(200);
})
.ToolBar(toolbar => toolbar.Create()) // The "create" command adds new data items
.Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode
.DataSource(dataSource =>
dataSource.Ajax()
.Model(model =>
{
model.Id(student => student.StudentNumber); // Specify the property which is the unique identifier of the model
// model.Field(student => student.StudentNumber).Editable(false); // Make the studentID property not editable
// model.Field(p => p.CustomerNames).DefaultValue(
// ViewData["defaultCategory"] as KendoGridAjaxEditing2.Models.CustomerNamesViewModel);
})
.Create(create => create.Action("BoardingPoints_Create", "Student")) // Action invoked when the user saves a new data item
.Read(read => read.Action("BoardingPoints_Read", "Student")) // Action invoked when the grid needs data
.Update(update => update.Action("BoardingPoints_Update", "Student")) // Action invoked when the user saves an updated data item
.Destroy(destroy => destroy.Action("BoardingPoints_Destroy", "Student")) // Action invoked when the user removes a data item
)
.Pageable()
%>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult students_Create([DataSourceRequest]DataSourceRequest request, StudentsViewModel students)
{
var results = new List<StudentsViewModel>();
if (students != null )//&& ModelState.IsValid)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.InsertSchoolYear(students, _studNum);
results.Add(students);
}
return Json(results.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult students_Update([DataSourceRequest]DataSourceRequest request, StudentsViewModel students)
{
if (students != null && ModelState.IsValid)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.UpdateSchoolYear(students);
UpdateModel(students);
}
return Json(new[] { students }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult students_Destroy([DataSourceRequest]DataSourceRequest request, StudentsViewModel product)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.DeleteSchoolYear(product);
return Json(new[] { product }.ToDataSourceResult(request, ModelState));
}
public ActionResult BoardingPoints_Read([DataSourceRequest] DataSourceRequest request)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
return Json(StudentRepository.GetSBoardingPoint(_studNum).ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult BoardingPoints_Create([DataSourceRequest]DataSourceRequest request, StudentsViewModel students)
{
var results = new List<StudentsViewModel>();
if (students != null )
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.InsertBoardingPoint(students, _studNum);
results.Add(students);
}
return Json(results.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult BoardingPoints_Update([DataSourceRequest]DataSourceRequest request, StudentsViewModel students)
{
if (students != null )
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.UpdateBoardingPoint(students);
UpdateModel(students);
}
return Json(new[] { students }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult BoardingPoints_Destroy([DataSourceRequest]DataSourceRequest request, StudentsViewModel product)
{
_studNum = HttpContext.Session["StudentNumber"].ToString();
StudentRepository.DeleteBoardingPoint(product);
return Json(new[] { product }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
}