【问题标题】:View Database Columns via Checkbox WebFrom and Cookies通过复选框 WebForm 和 Cookie 查看数据库列
【发布时间】:2011-09-23 16:37:01
【问题描述】:

我正在使用 Telerik MVC 模板,并且有一个包含大量列的数据库,并且 Telerik 网格没有水平滚动条,因此我创建了复选框,以供用户准确选择他们想要查看的列。它工作得很好,当我第一次进入页面时,它会在顶部显示带有“应用”按钮的复选框和下方的网格视图。由于尚未从 WebForm 提交任何内容,因此网格视图显示了所有列。在添加 cookie 之前,用户只需按一次应用,这些列就会出现。但是,如果用户随后尝试对这些列之一进行排序或过滤,它将恢复为显示所有列。因此,我创建了一个 cookie 来存储所选信息。不幸的是,这只有助于选择第一个过滤器。如果使用第二个过滤器,它将再次显示所有列,而不仅仅是选定的列。此外,用户现在必须按两次应用才能在网格视图上正确显示他们的选择。以下是我如何对所有内容进行编码的简要说明:

索引视图

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm("Index", "Order"))
   { %>
    <p>
        <%= Html.CheckBox("osurr", true, "Ad Number")%>Ad Number        //I set this and a few other columns to default to true
        <%= Html.CheckBox("csurr", false, "Customer Number")%>Customer Number
        <%= Html.CheckBox("rhosurr", false, "RHO Number")%>RHO Number
        <%= Html.CheckBox("lockid", false, "Lock ID")%>Lock ID
                                //And several more
    </p>
    <input type="submit" value="Apply" />
<% } %>
<%
    Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
                     {
                         columns.Template(o =>
                                              {
%>
                      <%=Html.ActionLink("Detail", "Edit", new { id = o.osurr })%>
                  <%
                                              }).Width(25);


                         if (Request.Cookies["DBCols"]["csurr"] != null)
                     {
                         if (Request.Cookies["DBCols"].Values["csurr"].Equals("True")) { columns.Bound(o => o.csurr).Title("Cust. No."); }
                     }
                     if (Request.Cookies["DBCols"]["rhosurr"] != null)
                     {
                         if (Request.Cookies["DBCols"].Values["rhosurr"].Equals("True")) { columns.Bound(o => o.rhosurr).Title("RHO No."); }
                     }
                     if (Request.Cookies["DBCols"]["lockid"] != null)
                     {
                         if (Request.Cookies["DBCols"].Values["lockid"].Equals("True")) { columns.Bound(o => o.lockid).Title("Lock ID"); }
                     }
                                                                                                    //And again, several more.
                     })
        .Groupable(grouping => grouping.Enabled(true))
        .Resizable(resizing => resizing.Columns(true))
        .Filterable(filter => filter.Enabled(true))
        .Sortable(sorting => sorting.Enabled(true))
        .Pageable(paging => paging.Enabled(true).PageSize(25))
        .Render();   
%>


</asp:Content>

控制器

public ActionResult Index(bool? csurr, bool? rhosurr, bool? lockid /* And Several More */)
{
ViewData["csurr"] = csurr ?? true;
ViewData["rhosurr"] = rhosurr ?? true;
ViewData["lockid"] = lockid ?? true;

if ((bool)ViewData["csurr"]) { DBCols.Values["csurr"] = (ViewData["csurr"].ToString());
}
else { DBCols.Values["csurr"] = "False"; }
if ((bool)ViewData["rhosurr"]) { DBCols.Values["rhosurr"] = (ViewData["rhosurr"].ToString()); }
else { DBCols.Values["rhosurr"] = "False"; }
if ((bool)ViewData["lockid"]) { DBCols.Values["lockid"] = (ViewData["lockid"].ToString()); }
else { DBCols.Values["lockid"] = "False"; }
//And Several more

var db = new MillieOrderDB();
var listView = from m in db.vw_cadords
orderby m.createstamp descending
select m;
return View(listView);
}

我现在只在 Index ActionResult 中工作,以便在我弄清楚如何让这一切正常工作的同时将事情保存在一个地方。任何人都知道为什么我必须按两次应用,为什么我不能使用多个过滤器,以及如何避免这种情况?

【问题讨论】:

    标签: asp.net-mvc-3 cookies checkbox telerik-grid telerik-mvc


    【解决方案1】:

    事实证明,我必须点击两次应用以及应用多个过滤器导致问题的原因是因为我在 Index ActionResult 中拥有所有内容。一旦我将所有表单数据移动到它自己的 ActionResult,然后执行 RedirecttoAction("Index"),一切正常!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-20
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      相关资源
      最近更新 更多