dev Express グリッドを使用してインライン編集を取得しようとしています。http://mvc.devexpress.com/GridView/InlineEditingWithTemplateで述べた例に従い、 http://www.youtube.com/watch?v=dKCFLyvf32Yこのリンク を見て確認しました。私のコントローラーのコードは次のとおりです。
[ValidateInput(false)]
public ActionResult InlineEditingWithTemplatePartial()
{
int siteID = (int)Session["siteID"];
return PartialView("InlineEditingWithTemplatePartial", employeeRepo.GetAllEmployeesForSite(siteID));
}
[HttpPost, ValidateInput(false)]
public ActionResult InlineEditingWithTemplateAddNewPartial([ModelBinder(typeof(DevExpressEditorsBinder))] Employee employee)
{
int siteID = 0;
if (ModelState.IsValid)
{
try
{
siteID = (int)Session["siteID"];
//employee.InsertProduct(employee);
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
else
{
ViewData["EditError"] = "Please, correct all errors.";
ViewData["EmployeeDetail"] = employee;
}
return PartialView("InlineEditingWithTemplatePartial", employeeRepo.GetAllEmployeesForSite(siteID));
}
[HttpPost, ValidateInput(false)]
public ActionResult InlineEditingWithTemplateUpdatePartial([ModelBinder(typeof(DevExpressEditorsBinder))] Employee employee)
{
int siteID = 0;
if (ModelState.IsValid)
{
try
{
siteID = (int)Session["siteID"];
employeeRepo.SaveEmployee(employee);
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
else
{
ViewData["EditError"] = "Please, correct all errors.";
ViewData["EnployeeDetail"] = employee;
}
return PartialView("InlineEditingWithTemplatePartial", employeeRepo.GetAllEmployeesForSite(siteID));
}
[HttpPost, ValidateInput(false)]
public ActionResult InlineEditingWithTemplateDeletePartial(Employee employee)
{
int siteID = 0;
if (employee!=null)
{
try
{
siteID = (int)Session["siteID"];
employeeRepo.DeleteEmployee(employee);
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
return PartialView("InlineEditingWithTemplatePartial", employeeRepo.GetAllEmployeesForSite(siteID));
}
ビューのコードは次のとおりです。
@using MyProject6.Data.Models;
@using System.Web.UI.WebControls;
@using DevExpress.Web.Mvc.UI;
@using DevExpress.Web.ASPxEditors;
@using DevExpress.Web.Mvc;
@using DevExpress.Web.ASPxGridView;
@{
var grid = Html.DevExpress().GridView(
settings =>
{
settings.Name = "gvEmployeeEditing";
settings.KeyFieldName = "EmployeeID";
settings.CallbackRouteValues = new { Controller = "Home", Action = "InlineEditingWithTemplatePartial" };
settings.ClientSideEvents.BeginCallback = "function(s,e){e.customArgs['id'] = '" + ViewContext.RouteData.Values["EmployeeID"] + "'}";
settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Home", Action = "" }; //InlineEditingUpdatePartial
settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Home", Action = "InlineEditingWithTemplateUpdatePartial"};
settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Home", Action = "" }; //InlineEditingUpdatePartial
settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
settings.SettingsBehavior.ConfirmDelete = true;
settings.CommandColumn.Visible = true;
settings.CommandColumn.NewButton.Visible = true;
settings.CommandColumn.DeleteButton.Visible = true;
settings.CommandColumn.EditButton.Visible = true;
settings.Columns.Add("EmployeeID");
settings.Columns.Add("EmployeeCode");
settings.Columns.Add("FirstName");
settings.Columns.Add("LastName").PropertiesEdit.DisplayFormatString = "c";
settings.Columns.Add("DefaultRoleTitle");
settings.SetEditFormTemplateContent(c => {
var employee = ViewData["EditableEmployeeDetail"] != null ? ViewData["EditableEmployeeDetail"] : c.DataItem;
ViewContext.Writer.Write(
"<div class=\"edit_form\">" +
"<div class=\"line\">"
);
Html.DevExpress().Label(
edtSettings => {
edtSettings.ControlStyle.CssClass = "label";
edtSettings.Text = "Employee Code";
edtSettings.AssociatedControlName = "EmployeeCode";
}
)
.Render();
Html.DevExpress().TextBox(
edtSettings => {
edtSettings.Name = "EmployeeCode";
edtSettings.ControlStyle.CssClass = "editor";
edtSettings.ShowModelErrors = true;
}
)
.Bind(DataBinder.Eval(employee, "EmployeeCode"))
.Render();
ViewContext.Writer.Write(
"</div>" +
"<div class=\"line\">"
);
Html.DevExpress().Label(
edtSettings => {
edtSettings.ControlStyle.CssClass = "label";
edtSettings.Text = "First Name:";
edtSettings.AssociatedControlName = "FirstName";
}
)
.Render();
Html.DevExpress().TextBox(
edtSettings =>
{
edtSettings.Name = "FirstName";
edtSettings.ControlStyle.CssClass = "editor";
edtSettings.Text = "First Name";
edtSettings.ShowModelErrors = true;
}
).Bind(DataBinder.Eval(employee, "FirstName"))
.Render();
ViewContext.Writer.Write(
"</div>" +
"<div class=\"line\">"
);
Html.DevExpress().Label(
edtSettings => {
edtSettings.ControlStyle.CssClass = "label";
edtSettings.Text = "Last Name:";
edtSettings.AssociatedControlName = "LastName";
}
)
.Render();
Html.DevExpress().TextBox(
edtSettings => {
edtSettings.Name = "LastName";
edtSettings.ControlStyle.CssClass = "editor";
edtSettings.ShowModelErrors = true;
}
)
.Bind(DataBinder.Eval(employee, "LastName"))
.Render();
ViewContext.Writer.Write(
"</div>" +
"<div class=\"line\">"
);
Html.DevExpress().Label(
edtSettings =>
{
edtSettings.ControlStyle.CssClass = "label";
}
)
.Render();
Html.DevExpress().Button(
btnSettings =>
{
btnSettings.Name = "btnUpdate";
btnSettings.ControlStyle.CssClass = "button";
btnSettings.Text = "Update";
btnSettings.ClientSideEvents.Click = "function(s, e){ gvEmployeeEditing.UpdateEdit(); }";
}
)
.Render();
Html.DevExpress().Button(
btnSettings =>
{
btnSettings.Name = "btnCancel";
btnSettings.ControlStyle.CssClass = "button";
btnSettings.Text = "Cancel";
btnSettings.ClientSideEvents.Click = "function(s, e){ gvEmployeeEditing.CancelEdit(); }";
}
)
.Render();
ViewContext.Writer.Write(
"</div></div>"
);
});
settings.PreRender = (sender, e) =>
{
MVCxGridView gridView = (MVCxGridView)sender;
};
});
if(ViewData["EditError"] != null){
grid.SetEditErrorText((string)ViewData["EditError"]);
}
}
@grid.Bind(Model).GetHtml()
このビューは、ホーム コントローラーのインデックス ビューから呼び出す部分ビューです。デバッグしようとしましたが、インライン編集用のコードが入力されていません。何もコールバックしていないようです。ここで何が欠けているのかわからず、解決策を探すために過去 2 日間を費やしました。