1

我有一个部分视图。在这个部分视图中,我有一个 webgrid。我想从会话值绑定 gridview。我的代码是

@{
var properties = typeof(SLCCentral.Portal.Models.Entities.ApplicationModule).GetProperties();
var webGridColumns = properties.Select(prop => new WebGridColumn()
  {
      ColumnName = prop.Name,
      Header = prop.Name
   }).ToList();

              var grid = new WebGrid(source: Model, canSort: false, canPage: true, rowsPerPage: 10);
              var pager = grid.Pager();
              var index = grid.PageIndex;
              index = index + 1;
              var cnt = grid.PageCount;



              //var selectedIndex = "<span class=" + "webgrid-footer-selected" + ">" + index.ToString() + "</span>";
              var pgarrow = "class=" + "webgrid-footer-arrow" + "><img";
              var tblcss = "<table width=" + "100%" + " cellspacing=" + "0" + " cellpadding=" + "0" + " border=" + "0" + ">";
              var adthcss = "class=" + "HD-td-width-col_AppAddModule" + "> </th>";
              var epthcss = "class=" + "HD-td-width-col_AppEdit" + "> </th>";
              var dthcss = "class" + "HD-td-width-col_AppDelete" + "> </th>";
              // var pager = grid.Pager().ToString();
              if (index == 2)
              {

              }
              var tblHTML = grid.Table().ToHtmlString();

              //var Pager = System.Text.RegularExpressions.Regex.Replace(grid.Pager().ToString(), index.ToString(), selectedIndex);
              //var newPager = System.Text.RegularExpressions.Regex.Replace(pager, "(( \\d)|(\\d )|(<a([^a]*|a[^>])*a>))", "<span>$1</span>");
              var gridHtml = grid.GetHtml(footerStyle: "webgrid-footer-Group",
              mode: WebGridPagerModes.All, nextText: "Active-NXT", previousText: "Active-PRV", numericLinksCount: 5,
     columns: grid.Columns(



     grid.Column(columnName: "moduleName", header: "Modules Name", style: "HD-td-width-col_ModuleName", format: @<text><span class=" moduleName">@item.moduleName</span></text>),
     grid.Column(columnName: "moduleShortCode", header: "ModuleShortCode", style: "HD-td-width-col_ModuleName", format: @<text><span class=" moduleName">@item.moduleShortCode</span></text>),
     grid.Column(header: "Edit", style: "HD-td-width-col_AppEdit", format: @<text><span id="edit" style="cursor:pointer;text-decoration:underline;" onclick='doEdit("")'><img src="../../Images/edit-icon.png" alt="" width="18" height="19" title="Edit" /></span></text>),
     grid.Column(header: "Delete", style: "HD-td-width-col_AppDelete", format: @<text><span id="delete" style="cursor:pointer;text-decoration:underline;" onclick='PerformDelete("")'><img src="../../Images/delete-icon.png" alt="" width="16" height="21" title="Delete" /></span></text>))).ToString();



              //gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, index.ToString(), selectedIndex);
              gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, "<table>", tblcss);
              gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, ">AddModules</th>", adthcss);
              gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, ">Edit</th>", epthcss);
              gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, ">Delete</th>", dthcss);


              }@(new HtmlString(gridHtml))
    public void AddModule(string ModuleName, string ModuleShortcode)
        {
            try
            {
                if (!string.IsNullOrEmpty(ModuleName))
                {
                    _objIApplicationManagerBAL.SetModuleCol(ModuleName, ModuleShortcode);
                    _objIApplicationModuleCol = _objISessionContext.IModuleContextCol;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
          }
4

1 回答 1

1

您可以使用 callscript和 by在网格中绑定值Partialview

Script

<script type="text/javascript">
  $(document).ready(function () {
 firstDDLValue = "Your Session Value"
 $.get('@Url.Action("YourMethod")', { secondValue: firstDDLValue }, function (result) {
 $('#div-grid-id').html(result);
 });
});
</script>

Control:

public ActionResult YourMethod(Viewname model, string secondValue)
{
    if (secondValue != "")
    ObservableCollection<Yourviewnam> Yourviewnam= new ObservableCollection<Yourviewnam>();
    Yourviewnam Yourviewnam= new Models.Yourviewnam();
    result= Receipt.GetReceiptListByCustID(secondValue);
    return PartialView("PratialViewname", result);
}

像在主视图中一样创建PartialView cshtml并编写gridview的代码..我觉得它会很好用。

于 2013-10-08T09:23:47.853 回答