按钮 OnClick=“btnSave_Click”不适用于 MVC 应用程序

发布于 2024-10-18 17:32:38 字数 3254 浏览 0 评论 0原文

我是 MVC 架构的新手,我正在努力获取 Button onclick。请帮我追踪问题。我有一个已填充的 Telerik TreeView 控件。有些节点有子节点,有些则没有。

请让我知道需要进行哪些更改才能解决该问题 在这里,我正在努力让它发挥作用。

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/PostLogin.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<applications>>" %>

<%@ Import Namespace="ApplicationGrps" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>


<script runat="server" type="text/javascript">

    protected void Page_Load()
    {

        ApplicationGrps.Visible = true;
        ApplicationGrps.DataSource = ODS1;

        ApplicationGrps.DataFieldID = "ApplicationName";
        ApplicationGrps.DataFieldParentID = "ParentID";

        ApplicationGrps.DataBind();
        BindCheckedTags(ApplicationGrps);
    }

    protected void BindCheckedTags(RadTreeView treeView)
        {
          // Displays the checked nodes
        }


        protected void ODS2_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            e.InputParameters["ClientID"] = ViewData["ClientID"];
        }

    protected void btnSave_Click(object sender, EventArgs e)
        {
               //Iterate through the tree and get all the nodes that are checked and submit it.
        }
</script>


<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="<%: Url.Content("~/Content/script-libraries/jquery-ui-1.7.2.custom/css/smoothness/jquery-ui-1.7.2.custom.css") %>"
        rel="stylesheet" type="text/css" />
    <script src="<%: Url.Content("~/Scripts/jquery-1.4.1.js") %>" type="text/javascript"></script>

</asp:Content>


<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <form id="form1" runat="server" method="post">

     <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>

       <telerik:RadTreeView id="AppModulesTreeView" runat="server" CheckBoxes="True" Visible="true" >


</telerik:RadTreeView>

<asp:ObjectDataSource ID="ODS1" runat="server" 
    SelectMethod="GetAllApplicationModules"
    TypeName="ELS.BOS.Services.EntitlementProxy.EntitlementServiceClient">
</asp:ObjectDataSource>

<asp:ObjectDataSource ID="ODS2" runat="server" 
    SelectMethod="GetApplicationModMappedByClientID" 
    TypeName="ELS.BOS.Services.EntitlementProxy.EntitlementServiceClient" 
          onselecting="ODS2_Selecting">
    <SelectParameters>
        <asp:Parameter Name="ClientID" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>
      <%--  <telerik:RadButton runat="server" onclick="btnSave_Click" 
            Text="Save">
        </telerik:RadButton>
        <telerik:RadButton ID="btnCancel" runat="server" Text="Cancel" 
            >
        </telerik:RadButton>--%>


        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="btnSave_Click" />

    </div>
    </form>


</asp:Content>

如果我需要使用 javascript 或 jquery 来完成此工作,请告诉我。请向我展示一些有关如何在按钮控件单击时触发 btnSave_click 的示例。

谢谢!

I am new to MVC architecture and I am struggling to get the Button onclick. Please help me trace the issue. I have a Telerik TreeView control, which is populated. Some of the nodes have child nodes and some of them doesn't.

Please let me know what changes need to be made to fix the issue
Here I am struggling to get it working.

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/PostLogin.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<applications>>" %>

<%@ Import Namespace="ApplicationGrps" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>


<script runat="server" type="text/javascript">

    protected void Page_Load()
    {

        ApplicationGrps.Visible = true;
        ApplicationGrps.DataSource = ODS1;

        ApplicationGrps.DataFieldID = "ApplicationName";
        ApplicationGrps.DataFieldParentID = "ParentID";

        ApplicationGrps.DataBind();
        BindCheckedTags(ApplicationGrps);
    }

    protected void BindCheckedTags(RadTreeView treeView)
        {
          // Displays the checked nodes
        }


        protected void ODS2_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            e.InputParameters["ClientID"] = ViewData["ClientID"];
        }

    protected void btnSave_Click(object sender, EventArgs e)
        {
               //Iterate through the tree and get all the nodes that are checked and submit it.
        }
</script>


<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="<%: Url.Content("~/Content/script-libraries/jquery-ui-1.7.2.custom/css/smoothness/jquery-ui-1.7.2.custom.css") %>"
        rel="stylesheet" type="text/css" />
    <script src="<%: Url.Content("~/Scripts/jquery-1.4.1.js") %>" type="text/javascript"></script>

</asp:Content>


<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <form id="form1" runat="server" method="post">

     <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>

       <telerik:RadTreeView id="AppModulesTreeView" runat="server" CheckBoxes="True" Visible="true" >


</telerik:RadTreeView>

<asp:ObjectDataSource ID="ODS1" runat="server" 
    SelectMethod="GetAllApplicationModules"
    TypeName="ELS.BOS.Services.EntitlementProxy.EntitlementServiceClient">
</asp:ObjectDataSource>

<asp:ObjectDataSource ID="ODS2" runat="server" 
    SelectMethod="GetApplicationModMappedByClientID" 
    TypeName="ELS.BOS.Services.EntitlementProxy.EntitlementServiceClient" 
          onselecting="ODS2_Selecting">
    <SelectParameters>
        <asp:Parameter Name="ClientID" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>
      <%--  <telerik:RadButton runat="server" onclick="btnSave_Click" 
            Text="Save">
        </telerik:RadButton>
        <telerik:RadButton ID="btnCancel" runat="server" Text="Cancel" 
            >
        </telerik:RadButton>--%>


        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="btnSave_Click" />

    </div>
    </form>


</asp:Content>

Please let me know if I need to use javascript or jquery to get this working. Please show me some samples on how to fire btnSave_click on button control click.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘味果▽酱 2024-10-25 17:32:38

, asp:ObjectDataSource, ScriptManager,...在 ASP.NET MVC 应用程序中?

否。

在 ASP.NET MVC 应用程序中,您不使用服务器端控件(无 runat="server")。你不回发。没有 ViewState。后面没有代码。没有事件。没有脚本管理器。没有对象数据源。所有这些都是 WebForms 特有的,并且不再在 MVC 中使用。

在 ASP.NET MVC 应用程序中,您有一个控制器、一个模型和一个视图。该视图包含标准 HTML 标记,可以借助 HTML 帮助程序生成。要调用控制器,您可以使用普通链接:

<%= Html.ActionLink("link text", "actionName", "controllerName") %>

控制器包含操作模型的操作,并通过向其传递需要显示的所有信息来选择要呈现的视图。

我强烈建议您开始阅读此处的教程:http://asp.net/mvc 了解 MVC 的工作原理并熟悉该框架的基础知识。

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="btnSave_Click" />, asp:ObjectDataSource, ScriptManager, ... in an ASP.NET MVC application?

No.

In an ASP.NET MVC applications you don't use server side controls (no runat="server"). You don't PostBack. There is no ViewState. There is no code behind. There are no events. There are no script managers. There are no object data sources. All this is specific to WebForms and is no longer used in MVC.

In an ASP.NET MVC application you have a Controller, a Model and a View. The view contains standard HTML markup which could be generated with the aid of HTML helpers. To call the controller you could use a normal link:

<%= Html.ActionLink("link text", "actionName", "controllerName") %>

The controller contains actions which manipulate the model and choose the view to be rendered by passing it all the information it needs to show.

I would strongly recommend you start reading the tutorials here: http://asp.net/mvc about how MVC works and familiarize yourself with the very basics of this framework.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文