`

MVC ASP页面叫Control的各种方法

阅读更多
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<com.nowdocs.nowsource.Admin.ViewModels.SiteConfiguration.SALevelListViewModel>" %>
<script type='text/javascript'>
    $(function () {
        $('li').click(function () {
            $('#SelectID').val($(this).children(':input').val());
            $('ul li').removeClass("selected");
            $(this).addClass("selected");

        });
         //方法一
        $('#btn_del').click(function (e) {
            var sid = $('#SelectID').val();
            if (sid != null && sid != '' && sid != '0') {
                e.preventDefault();
                location.href = '<%= Url.Action("Delete","SalesAdminLevelNew")%>' + '/' + sid;
                //location.href = 'Delete/' + sid;
            }
            else
                $(this).val("0");
        });

        $('#btn_activate').click(function (e) {
            var sid = $('#SelectID').val();
            if (sid != null && sid != '' && sid != '0') {
                e.preventDefault();
                location.href = '<%= Url.Action("UpdateSalesAdminLevelActive","SalesAdminLevelNew")%>' + '/' + sid;

                //location.href = 'Delete/' + sid;方法二注掉了,有时候URL会拼写错误,不建议使用
            }
            else
                $(this).val("0");
        });
    });
</script>
<div id="group-list" class="admin-panel" style="width: 400px;">
    <div class="title">
        <%: com.nowdocs.nowsource.Admin.Resources.SalesAdminLevel.SALevelTitle %>
    </div>
    <div class="content">
        <div class="wrap" id="ChildGroupList" style="display: block;">
            <ul>
                <% if (Model.SALevelList != null)
                   {
                       foreach (var link in Model.SALevelList)
                       {
                           if (link.IsSelected)
                           {%>
                <li class="selected">
                    <%}
                           else
                           { %>
                    <li>
                        <%} %>
                        <a>
                            <%: link.Text%></a><%: Html.Hidden("SalesAdminLevelID", link.intSalesAdminLevelID)%></li>
                    <%
                       }
                   }%>
            </ul>
        </div>
        <div class="viewedit">
            <%: Html.Hidden("SelectID")%>
<!--方法三-->
            <input type="submit" id="btn_add" value="Add" onclick='this.form.action="<%= Url.Action("AddSetting") %>";' />
<!--方法四-->
            <input type="submit" id="btn_edit" value="Edit" onclick='this.form.action="<%= Url.Action("Edit1") %>";' />
            <input type="button" id="btn_del" value="Delete" />
            <input type="button" id="btn_activate" value="Activate/Deactivate" />
        </div>
    </div>
</div>

 Control.cs

using System;
using System.Collections.Generic;
using System.Web.Mvc;
using com.nowdocs.nowsource.Admin.BusinessLogic.SiteConfiguration;
using com.nowdocs.nowsource.Admin.ViewModels.SiteConfiguration;
using com.nowdocs.nowsource.common;
using com.nowdocs.nowsource.Models;
using log4net;

namespace com.nowdocs.nowsource.Admin.Controllers.SiteConfiguration
{
    public class SalesAdminLevelNewController : AdminController
    {
        protected static readonly ILog logger = LogManager.GetLogger("SalesAdminLevelController");

        public GroupModel CurrentGroup
        {
            get
            {
                return StateManager.CurrentGroup;
            }
            set
            {
                StateManager.CurrentGroup = value;
            }
        }

        public SalesAdminLevelNewController() : base() { }

        //
        // GET: /SalesAdminLevel/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetSALevelList(int id)
        {
            List<SalesAdminLevelModel> saLevelList = SalesAdminLevelBL.GetSalesAdminLevelList();

            SALevelListViewModel savm = new SALevelListViewModel();
            savm.SelectID = id;
            savm.SALevelList = new List<SALevelListItemViewModel>();

            if (saLevelList.Count > 0)
            {
                foreach (var item in saLevelList)
                {
                    SALevelListItemViewModel salm = new SALevelListItemViewModel();
                    salm.intSalesAdminLevelID = item.intSalesAdminLevelID;

                    string isActive = item.blnSalesAdminLevelActive ? "" : "(Inactive)";
                    salm.Text = (item.strSalesAdminLevelName + isActive).Trim();
                    if (salm.intSalesAdminLevelID == id)
                    {
                        salm.IsSelected = true;
                    }
                    else
                    {
                        salm.IsSelected = false;
                    }

                    savm.SALevelList.Add(salm);
                }
            }

            //ViewData["ViewEdit"] = GetViewEdit();
            ViewBag.SalesAdminLevelID = id;
            return View("SalesAdminLevelListNew", savm);
        }

        /// <summary>
        /// Display Edit View
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult EditView(UserTypeListViewModel model)
        {
            //var session = SessionManager.Current;
            CurrentGroup = null;
            if (model.ViewEdit.Equals("1"))
                return RedirectToAction("Add", new { id = 0 });
            if (model.ViewEdit.Equals("2"))
                return RedirectToAction("Edit", new { id = model.SelectID });
            if (model.ViewEdit.Equals("3"))
                return RedirectToAction("Delete", new { id = model.SelectID });
            if (model.ViewEdit.Equals("4"))
                return RedirectToAction("UpdateSalesAdminLevelActive", new { id = model.SelectID });
            return View();
        }

        #region GetViewEdit()

        public static SelectList GetViewEdit()
        {
            List<SelectListItem> item = new List<SelectListItem>();

            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.Select, Value = "0" });
            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.AddSALevel, Value = "1" });
            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.EditeSALevel, Value = "2" });
            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.DeleteSALevel, Value = "3" });
            item.Add(new SelectListItem { Text = Resources.SalesAdminLevel.ActivateOrDeactivate, Value = "4" });
            return new SelectList(item, "Value", "Text");
        }

        #endregion GetViewEdit()

        //
        // GET: /SalesAdminLevel/Create

        [HttpPost]
        [ActionName("AddSetting")]
        public ActionResult Add(SALevelListViewModel model)
        {
            SalesAdminLevelViewModel salvm = new SalesAdminLevelViewModel();
            return View(salvm);
        }

        //
        // POST: /SalesAdminLevel/Create

        [HttpPost]
        public ActionResult Add(SalesAdminLevelViewModel viewmodel)
        {
            try
            {
                SalesAdminLevelModel temp = new SalesAdminLevelModel();
                temp.strSalesAdminLevelName = viewmodel.strSalesAdminLevelName;
                if (SalesAdminLevelBL.isSalesAdminLevelRepeat(temp))
                {
                    ModelState.AddModelError("sameSALevelName", Resources.SalesAdminLevel.sameSALevelName);
                    throw new Exception();
                }
                else
                {
                    viewmodel.blnSalesAdminLevelActive = true;
                    SalesAdminLevelModel temputm = SalesAdminLevelBL.SaveSalesAdminLevel(viewmodel.ToSalesAdminLevelModel());
                }
                return RedirectToAction("Index");
            }
            catch
            {
                return View(viewmodel);
            }
        }

        //
        // GET: /SalesAdminLevel/Edit/5
        [HttpPost]
        public ActionResult Edit1(SALevelListViewModel model)
        {
            return RedirectToAction("Edit", new { id = model.SelectID });
        }

        //
        // GET: /SalesAdminLevel/Edit/5

        public ActionResult Edit(int id)
        {
            SalesAdminLevelModel utm = new SalesAdminLevelModel();
            utm.intSalesAdminLevelID = id;
            utm = SalesAdminLevelBL.GetSalesAdminLevelInfo(utm);

            SalesAdminLevelViewModel utViewModel = new SalesAdminLevelViewModel(utm);

            ViewBag.SALevelID = id;
            return View(utViewModel);
        }

        //
        // POST: /SalesAdminLevel/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, SalesAdminLevelViewModel utvm)
        {
            try
            {
                SalesAdminLevelModel temp1 = new SalesAdminLevelModel();
                temp1.strSalesAdminLevelName = utvm.strSalesAdminLevelName;
                temp1.intSalesAdminLevelID = id;
                ViewBag.SALevelID = id;
                if (SalesAdminLevelBL.isSalesAdminLevelRepeat(temp1))
                {
                    ModelState.AddModelError("sameSALevelName", Resources.SalesAdminLevel.sameSALevelName);
                    temp1 = null;
                    throw new Exception();
                }
                else
                {
                    utvm.intSalesAdminLevelID = id;
                    SalesAdminLevelModel temputm = SalesAdminLevelBL.UpdateSalesAdminLevel(utvm.ToSalesAdminLevelModel());
                }

                return RedirectToAction("index");
            }
            catch (Exception ex)
            {
                SalesAdminLevelModel userTypeModelexp = utvm.ToSalesAdminLevelModel();
                return View(new SalesAdminLevelViewModel(userTypeModelexp));
            }
        }

        //
        // GET: /SalesAdminLevel/Delete/5

        public ActionResult Delete(int id)
        {
            SalesAdminLevelModel utm = new SalesAdminLevelModel();
            utm.intSalesAdminLevelID = id;

            //utm = SalesAdminLevelBL.GetSalesAdminLevelByid(utm);

            if (utm != null)
            {
                SalesAdminLevelBL.DeleteSalesAdminLevel(utm);
            }

            return RedirectToAction("Index");
        }

        //
        // POST: /SalesAdminLevel/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, SALevelListViewModel utvm)
        {
            try
            {
                SalesAdminLevelModel temp = new SalesAdminLevelModel();
                temp.intSalesAdminLevelID = utvm.SelectID;

                if (temp != null)
                {
                    SalesAdminLevelBL.DeleteSalesAdminLevel(temp);
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View(utvm);
            }
        }

        public ActionResult UpdateSalesAdminLevelActive(int id)
        {
            SalesAdminLevelViewModel utm = new SalesAdminLevelViewModel();
            utm.intSalesAdminLevelID = id;
            SalesAdminLevelBL.UpdateSalesAdminLevelActive(utm.ToSalesAdminLevelModel());

            return RedirectToAction("index");
        }
    }
}
 
分享到:
评论

相关推荐

    asp.net mvc admin user control

    Admin User Control是ASP.NET MVC应用中常见的组件,主要用于实现后台管理界面中的用户控制功能,比如用户注册、登录、权限管理等。 在ASP.NET MVC中,"Admin Level Control"可能指的是具有管理员权限级别的控制...

    asp.net MVC4 CMS

    ASP.NET MVC4使用路由机制来解析URL,并将其映射到相应的控制器和操作方法。开发者可以通过配置路由规则来定制URL结构,使其更符合SEO(搜索引擎优化)的要求。 **依赖注入(Dependency Injection)**: ASP.NET ...

    ASP.NET MVC Tabbed Menu Control

    ASP.NET MVC Tabbed Menu Control.Source Code. http://www.dev102.com/2009/04/14/creating-a-tabbed-menu-control-for-aspnet-mvc/

    AspMvc框架 v1.1

    AspMvc是一个快速、简单的面向对象的轻量级Asp开发框架,是为了简化企业级应用开发和敏捷WEB应用开发而诞生的。 借鉴了国内外很多优秀的(Java Ssh/Net NetMvc3.5 ThinkPhp)框架和模式,使用面向对象的开发结构和MVC...

    asp .net mvc教程

    此外,ASP.NET MVC还提供了依赖注入(Dependency Injection,DI)和控制反转(Inversion of Control,IoC)机制,这使得代码更加松耦合,便于测试和维护。通过注册服务容器,我们可以方便地在控制器和其他组件之间...

    ASP.NET MVC Entity Framework

    ASP.NET MVC(Model-View-Controller)是一种基于微软.NET Framework的Web应用程序开发框架,它用于构建可维护性和可测试性极高的动态网站。MVC模式将应用程序分为三个主要部分:模型(Model)、视图(View)和控制...

    ASP.NET_MVC_Framework_Unleashed

    此外,ASP.NET MVC支持AJAX集成,允许创建异步交互的用户体验,无需页面刷新。通过jQuery和其他JavaScript库,可以轻松实现客户端脚本交互。 总之,ASP.NET MVC Framework Unleashed这本书将全面讲解如何利用这个...

    Learning ASP.NET Core MVC Programming

    "Learning ASP.NET Core MVC Programming" English | ISBN: 1786463830 | 2016 | EPUB | 342 pages | 17 MB Key Features Get a first-principles coverage of ASP.NET MVC and the latest release, Core This book...

    Pro ASP.NET MVC Framework.pdf

    2. **ASP.NET MVC架构**:探讨了框架的内部工作原理,包括路由系统、控制器、动作方法、视图引擎、视图数据和辅助方法等。 3. **模型绑定**:讨论了如何通过模型绑定将HTTP请求数据映射到模型对象,简化了数据处理...

    Test-Drive ASP.NET MVC

    ASP.NET MVC 2.0 lets you test drive your code, control the output of your HTML, and leverage C# and .NET in an easy-to-use web framework. This book shows you all you need to know to get started ...

    ASP.NET MVC4 MVC5源码

    4. **路由(Routing)**:ASP.NET MVC中的路由系统决定了URL如何映射到控制器方法。 5. **过滤器(Filters)**:这些是可重用的代码片段,如授权、异常处理和动作筛选器,可以在全局或特定控制器/操作上应用。 6. **...

    ASP.NET MV 4,MVC5源码

    ASP.NET MVC是一个强大的Web应用程序开发框架,由微软公司推出,用于构建可维护、高性能的Web应用。MVC(Model-View-Controller)模式是其核心设计原则,它将应用程序分为三个主要部分:模型(Model)、视图(View)...

    ASP.NET MVC Awesome Jquery Control 破解版

    非常好用的ASP.NET MVC控件,提供大量实用的的页面技术 访问地址 http://awesome.codeplex.com/ 具体请参考范例 下载官网代码,然后替换此文件中的dll,就可以不受限制的使用了

    NIIT mvc3的asp.net试题

    1. 用户控件创建:在ASP.NET中,创建用户控件时,必须在文件的第一行包含`&lt;%@Control %&gt;`指令,并且用户控件的后缀名必须为`.ascx`。因此,选项A和D是正确的。 2. 动态编译与代码访问:`App_Code`文件夹是ASP.NET中...

    基于ASP.NET的IT人才招聘系统_MVC框架实现_论文

    ASP.NET的核心特性包括自动页面生命周期管理、内置的安全机制和状态管理解决方案。 【MVC框架】MVC(Model-View-Controller)是一种设计模式,广泛应用于Web应用开发,旨在分离业务逻辑、数据模型和用户界面。在ASP...

    ASP.NET MVC4 Web 编程 真正完整版PDF

    6. **异步控制器**:ASP.NET MVC4支持异步操作,利用.NET Framework 4.0的Task Parallel Library (TPL),可以编写非阻塞的控制器方法,提升服务器性能。 7. **增强的测试支持**:通过模拟IHttpControllerSelector和...

    Pro.ASP.NET MVC4英文版与个人学习笔记

    10. **依赖注入(DI)和 inversion of control (IoC)**:ASP.NET MVC4支持DI/IoC容器,允许灵活地管理和替换组件,提升代码的可扩展性和可维护性。 个人学习笔记可能涵盖了对这些主题的深入理解和实践体会,包括...

    ASP.NET MVC 5高级编程 第五版

    此外,书中还会探讨依赖注入(Dependency Injection,DI)和控制反转(Inversion of Control,IoC),这两种设计模式在ASP.NET MVC 5中被广泛使用,能帮助实现松散耦合和可测试的代码。 对于数据库操作,ASP.NET ...

Global site tag (gtag.js) - Google Analytics