`

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

    asp.net mvc admin user control release dates

    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...

    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...

    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 MVC Awesome Jquery Control 破解版

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

    ASP.NET MVC Entity Framework

    ASP.NET MVC 与Using Entity Framework结合的例子 可以参看下

    ASP.NET MVC Framework Unleashed(Stephen Walther)

    In this book, world-renowned ASP.NET expert and member of the Microsoft ASP.NET team Stephen Walther shows experienced developers how to use Microsoft's new ASP.NET MVC Framework to build web ...

    ASP.NET MVC in Action

    Microsoft's brand new ASP.NET MVC Framework now offers a fully-supported way for developers to implement MVC architectures in ASP.NET applications. ASP.NET MVC in Action is a comprehensive guide to ...

    Mvc源代码下载

    ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and gives you full control over markup for enjoyable, agile development. ASP...

    Professional ASP.NET MVC 1.0原版第三部分

    but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript,...

    Professional ASP.NET MVC 1.0 原版第二部分

    but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript,...

    Professional ASP.NET MVC 1.0原版第四部分

    but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript,...

    Professional ASP.NET MVC 1.0原版第五部分

    but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript,...

    Professional ASP.NET MVC 1.0原版第六部分

    but if it had to be said it in a quick sentence: "ASP.NET MVC is ASP.NET Unplugged." ASP.NET MVC is a tinkerer's framework that gives you very fine-grained control over your HTML and Javascript,...

    Asp.Net MVC 后台管理系统登录功能(1.0.0)

    介绍后台管理登录功能,主要包括: 验证输入基本信息(登录名、密码长度) 登陆成功之后可以获取用户基本信息,并跳转到主界面 未登陆用户不可进入主界面 退出登录

    Microsoft - Programming Microsoft ASP.NET MVC May 2010

    Programming Microsoft ASP.NET MVC 592 pages Publisher: Microsoft Press; 1 edition (May 14, 2010) Language: English ISBN-10: 0735627142 ISBN-13: 978-0735627147 Delve into the features, ...

    MVC设计模式详细图解

    MVC详细图解 MVC详细图解 一目了然 看了就明白了 model view control

Global site tag (gtag.js) - Google Analytics