c# – 使用带有jquery ui对话框的telerik网格!

前端之家收集整理的这篇文章主要介绍了c# – 使用带有jquery ui对话框的telerik网格!前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在名为form.ascx的mvc用户控件中,我有一个名为“details”的div中包含的Telerik Grid.

从一个名为edit.aspx的页面我写了以下内容

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="details">
        <%Html.RenderPartial("form",Model != null ? Model.CurrentEntity : null); %>
    </div>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $('#details').dialog(
            { modal: true,title: "add",width: 815,buttons: {
                    'save': function () { $("form:first").trigger("submit"); },'close': function () { $(this).dialog('close'); }
                }
            });
        });
    </script>
</asp:Content>

问题是对话框永远不会显示!!
并且用户控件显示在母版页内部,就好像我没有使用对话框一样.

在“表单”用户控件内部,当我禁用网格时,每件事情都正常工作,对话框显示正确.
当我使用萤火虫找出问题时,出现以下错误

$未定义????

任何身体都有想法?

这是主页面

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
    <%@ Import Namespace="Telerik.Web.Mvc.UI" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <link type="text/css" href="../../Content/Site.css" rel="stylesheet" />
        <link type="text/css" href="../../content/css/start/jquery-ui-1.8.2.custom.css" rel="Stylesheet" />
        <script type="text/javascript" src="/Scripts/jquery-1.4.2.js"></script>
        <script type="text/javascript" src="/Scripts/jquery-ui-1.8.2.custom.js"></script>
    <%--<script type="text/javascript" src="../../Scripts/Jquery.Validate.js"></script>--%>
        <%--<script type="text/javascript" src="../../Scripts/MicrosoftMvcJQueryValidation.js"></script>--%>
        <title>
            <asp:ContentPlaceHolder ID="TitleContent" runat="server" />
        </title>
    </head>
    <body>
    <%= Html.Telerik().StyleSheetRegistrar()
        .DefaultGroup(group => group.Add("telerik.common.css")
                                    .Add("telerik.outlook.css"))
<!----- some html content only ----->

        <div id="maincontent" class="fixed">
            <asp:ContentPlaceHolder ID="MainContent" runat="server">
            </asp:ContentPlaceHolder>
        </div>

    <asp:ContentPlaceHolder runat="server" ID="Footer" />
    <% Html.Telerik().ScriptRegistrar().DefaultGroup(group => { group.Add("telerik.examples.js").Compress(true); }).
           OnDocumentReady(() =>
           { %>prettyPrint();<% }).Render(); %>
</body>
</html>

这是局部视图form.acsx:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Bereau.Core.IncommingCorrespondence>" %>
<%@ Import Namespace="System.Web.Mvc.Html" %>
<%@ Import Namespace="BureauModule.Utility" %>
<%@ Import Namespace="Telerik.Web.Mvc.UI" %>
<%--<%= Html.ValidationSummaryJQuery("Error must be fixed.",new Dictionary<string,object> { { "id","valSumId" } })%>--%>
<%--<% Html.EnableClientValidation(); %>--%>
<% using (Html.BeginForm())
   { %>
<%=Html.DisplayFor (c=>c.Photocopy ) %>
<%--<% ViewContext.FormContext.ValidationSummaryId = "valSumId"; %>--%>
<form action="" method="post" id="customer_form" dir="rtl">
<div class="editor-label">
    <%:Html.LabelFor(c => c.Overstatment)%>
    <%=Html.TextBoxFor(c => c.Overstatment,new { @class ="text ui-widget-content ui-corner-all"})%>
    <%--<%= Html.ValidationMessageFor(model => model.Overstatment,"*") %>--%>
</div>
<div>
    <label for="CorrespondenceNumber">CorrespondenceNumber:</label>
    <%=Html.TextBoxFor(c => c.CorrespondenceNumber,new { @class = "text ui-widget-content ui-corner-all" })%>
    <span>
        <%--<%= Html.ValidationMessageFor(model => model.CorrespondenceNumber,"*")%>--%></span>
</div>
<div>
    <label for="Nature">Nature:</label>
    <%=Html.DropDownList("Nature")%>
    <%--<%= Html.ValidationMessageFor(model => model.Nature,"*")%>--%>
</div>
<div>
    <label for="Sender">Sender:</label>
    <%=Html.DropDownList("Sender")%>
    <%--<%= Html.ValidationMessageFor(model => model.Sender,"*")%>--%>
</div>
<div class="correspondenceReceiver">
    <% Html.Telerik().Grid<Bereau.Core.CorrespondenceDetail>(Model != null ? Model.Details : null)
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.CorrespondenceDetailID))
        .HtmlAttributes(new { @class = "t-grid-rtl" })
        .Columns(columns =>
        {
            columns.Bound(c => c.CorrespondenceDetailID).Visible(false);
            columns.Bound(c => c.Sender).Title("Sender");
            columns.Bound(c => c.Count).Title("Count");
            columns.Bound(c => c.Date).Title("Date").Format("{0:yyyy/MM/dd}");
            columns.Bound(c => c.Notes).Title("Notes");
            columns.Command(c => c.Edit());
        })
        .ToolBar(t => t.Insert())
        .DataBinding
        (c => c.Ajax()
            .Select("Select","IncommingCorespondence")
            .Insert("InsertDetail","IncommingCorespondence")
            .Update("UpdateDetail","IncommingCorespondence")
            )
        .Scrollable()
        .Sortable()
        .Pageable()
        .Render();
    %>
    <% Html.Telerik().ScriptRegistrar().OnDocumentReady(() =>
       {
    %>
    $('.insert-button').click(function(e) { e.preventDefault(); $('#Grid').data('tGrid').createRow();
    });
    <% }); %>
</div>
<input type="submit" runat="server" />
<% } %>
</form>

解决方法

当您使用Telerik ScriptRegistrar时,默认情况下它会在页面底部输出指向jQuery的链接.如果您的页面中的代码“更高”需要jQuery,或者您手动将jQuery添加页面中(就像您在代码示例中那样),则可以禁用ScriptRegistrar的行为,如下所示:
Html.Telerik().ScriptRegistrar().jQuery(false).Render();

另请注意,您不需要“telerik.examples.js”或“prettyPrint();”代码,除非您实际使用该代码.这些资源用于Telerik演示,但通常不在其他网站中使用.

您应该能够如上所示更新ScriptRegistrar,然后重新启用您的jQuery验证脚本而不会出现问题.

最后要注意的是,如果要使用ScriptRegistrar压缩,则需要在web.config中注册Asset HttpHandler:

<add verb="GET,HEAD" path="asset.axd" validate="false" type="Telerik.Web.Mvc.WebAssetHttpHandler,Telerik.Web.Mvc"/>

更多细节是available in the online docs.

猜你在找的C#相关文章