2012-12-10 85 views
0

我試圖使用dev express網格進行內聯編輯。我遵循 http://mvc.devexpress.com/GridView/InlineEditingWithTemplate 中所述的示例,並通過查看http://www.youtube.com/watch?v=dKCFLyvf32Y此鏈接進行確認。我控制器 代碼如下:dev表示mvc中的網格c#內聯編輯不擴展

[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() 

這種觀點是從我的家庭控制器的索引視圖調用局部視圖。 我試圖調試它,並沒有輸入內聯編輯的代碼。看起來它不回撥任何東西。 我不知道我在這裏錯過了什麼,我花了最近兩天尋找解決方案。

回答

0

我相信你可以使用E3998例子的解決方案。

如果您在實施過程中遇到任何問題,可以直接聯繫DX工作人員。

相關問題