第一次将view中列表提交到controller,尝试了下,还是可以的

要传输的实体类

    /// <summary>
/// 用于展示的角色类
/// </summary>
public class Action4Role
{
/// <summary>
/// 行为Id
/// </summary>
public string ActionId { get; set; }
/// <summary>
/// 角色Id
/// </summary>
public string RoleId { get; set; }
/// <summary>
/// 角色名字
/// </summary>
public string ActionName { get; set; }
/// <summary>
/// 所属项目名称
/// </summary>
public string ApplicationName { get; set; }
/// <summary>
/// 是否授权
/// </summary>
public bool IsAuthorize { get; set; }
}

get请求

        public ActionResult ActionRole(string RoleId)
{
var allActions = PowerService.GetActions().ToList();
var role = new Role4Select() { Id = RoleId };
var roles = PowerService.GetRoles(role).ToList();
ViewData["RoleName"] = PowerService.GetRoleById(RoleId).Name;
return View(roles);
}
@model List<DTOs.Role.Action4Role>

@{
ViewBag.Title = "ActionRole";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>行为角色</h2>
@using (Html.BeginForm("ActionRole", "Power", FormMethod.Get))
{
<div class="form-group">
<div class="col-md-10">
<p>@ViewData["RoleName"]</p>
</div>
</div>
}
@using (Html.BeginForm("SaveActionRoleList", "Power", FormMethod.Post))
{
<table class="table">
<tr>
<th>
全选<input type="checkbox" id="checkAll" />
</th>
<th>
行为
</th>
<th>
</th>
</tr> @for (int i = 0; i < Model.Count() ; i++)
{
@Html.HiddenFor(model => model[i].ActionId)
@Html.HiddenFor(model => model[i].RoleId)
@Html.HiddenFor(model => model[i].ApplicationName)
<tr>
<td>
@Html.CheckBoxFor(model => model[i].IsAuthorize)
</td>
<td>
@Html.DisplayTextFor(model => model[i].ActionName) </td>
</tr>
}
</table>
<div class="form-group">
<div class="col-md-offset-2 col-md-10 pull-left">
<input type="submit" value="保存" class="btn btn-default" />
</div>
</div>
}
<script src="~/Scripts/jquery-2.1.1.min.js"></script>
<script>
$(function () {
$('#checkAll').change(function () {
var isAll = document.getElementById('checkAll').checked;
$checkBoxs = $('input[type="checkbox"]').each(function () {
$(this).prop("checked", isAll);
})
})
})
</script>

post请求

        [AcceptVerbs(HttpVerbs.Post)]
public ActionResult SaveActionRoleList([Form]IEnumerable<Action4Role> actionList)
{
var roleId = actionList.First().RoleId;
var IsAuthRoleIds = actionList.Where(a => a.IsAuthorize).Select(a => a.ActionId);
var NoAuthRoleIds = actionList.Where(a => !a.IsAuthorize).Select(a => a.ActionId);
PowerService.RoleAddAction(roleId, IsAuthRoleIds.ToArray());
PowerService.RoleDeleteAction(roleId, NoAuthRoleIds.ToArray());
return RedirectToAction("RoleList");
}

以前总以为Model和字典在view和controller之间的通讯没有太多区别,也通过这个需求加深了对Model的理解.

加油,相信自己,明天可以的!

view向controller提交列表的更多相关文章

  1. ASP.NET MVC View向Controller提交数据

    我们知道使用MVC的一个很重的的用途就是把Controller和View之间进行解耦,通过控制器来调用不同的视图,这就注定了Controller和View之间的传值是一个很重的知识点,这篇博文主要解释 ...

  2. 从View向Controller传递复杂类型Json

    mvc给我们提供多种controller中读取view数据的方法 1.从Ruquest["name"]中直接读取 2.将表单中name名称直接写在Action的参数列表中 3.将表 ...

  3. Spring MVC基础知识整理➣View与Controller数据交互

    概述 Spring MVC是由View—Controller—Model组成,其中View和Controller的数据交互,成为了关注的核心点.MVC中,我们将View中的数据传递到Controlle ...

  4. 1、ASP.NET Core2.0之Model、View、Controller

    一.新建空项目 打开VS2017,新建→项目,选择如下: 点击,确定,弹出的界面选择如下: 选择空项目,因为选择其他的话会自动生成很多用不到的类,显得项目不够“清爽”,ASP.NET Core选择2. ...

  5. 【MVC架构】——怎样利用Json在View和Controller之间传递数据

    在MVC架构中,尽管非常多东西和三层非常相似,可是也有非常大的差别.就比方传递数据.在三层架构中,传递数据就仅仅要一层返回,另外一层用同样类型的变量来接收即可了.在MVC中,事实上原理是一样的,Con ...

  6. MVC 从View像Controller中传值

    在上一篇博客中总结了一下从Controller像View中传值的几种方法.事实上看那些方法和在我们最初学习VB的时候一样,将数据库中的数据显示到前台的页面.数据库还是那个数据库,仅仅是如今前台变成了浏 ...

  7. View 与 Controller 之间的delegate(代理)传值

    这个代理传值是经常使用的一种传值方式,下面介绍一种View 和 Controller 之间的代理传值方法. 先建立一个View视图 如 LoginView 是继承于一个UIView 在LoginVie ...

  8. AngularJS in Action读书笔记2——view和controller的那些事儿

    今天我们来818<angularjs in action>的第三章controller和view. 1.Big Picture概览图 View是angularjs编译html后呈现出来的, ...

  9. MVC(Model(模型) View(视图) Controller(控制器))

    复习 1.      商品表 增删改查 index.php  add.php   view.php   edit.php   action.php 2.      MVC(Model(模型)  Vie ...

随机推荐

  1. 优秀网站看前端 —— 小米Note介绍页面

    刚开始经营博客的时候,我写过不少“扒皮”系列的文章,主要介绍一些知名站点上有趣的交互效果,然后试着实现它们.后来开始把注意力挪到一些新颖的前端技术上,“扒皮”系列便因此封笔多时.今天打算重开“扒皮”的 ...

  2. js框架模版

    (function() { //注册命名空间zzw到window对象上 window['zzw'] = {} //定义一个$函数 function $() { alert("hello $& ...

  3. 用FlexGrid做开发,轻松处理百万级表格数据

    表格数据处理是我们项目开发中经常会遇到的设计需求之一,所需处理的数据量也较大,通常是万级.甚至百万级.此时,完全依赖平台自带的表格工具,往往无法加载如此大的数据量,或者加载得很慢影响程序执行. 那么, ...

  4. 《Entity Framework 6 Recipes》中文翻译系列 (11) -----第三章 查询之异步查询

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 第三章 查询 前一章,我们展示了常见数据库场景的建模方式,本章将向你展示如何查询实体 ...

  5. PHP的pcntl多进程

    PHP使用PCNTL系列的函数也能做到多进程处理一个事务.比如我需要从数据库中获取80w条的数据,再做一系列后续的处理,这个时候,用单进程?你可以等到明年今天了...所以应该使用pcntl函数了. 假 ...

  6. Leetcode-268 Missing Number

    #268.  Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...

  7. Java内部类的定义和使用

    为什么要用到内部类: 在java开发学习中我们经常会碰到内部类.内部类又有很多的优势:首先举一个简单的例子,如果你想实现一个接口,但是这个接口中的一个方法和你构想的这个类中的一个方法名称参数相同,你应 ...

  8. Sql Server系列:运算符和表达式

    运算符的一些符号,他们能够用于执行算术运算.字符串连接.赋值以及在字段.常量和变量之间进行比较.在SQL Server 2012中,运算符主要由以下6大类:算术运算符.赋值运算符.比较运算符.逻辑运算 ...

  9. LINQ系列:LINQ to XML类

    LINQ to XML由System.Xml.Linq namespace实现,该namespace包含处理XML时用到的所有类.在使用LINQ to XML时需要添加System.Xml.Linq. ...

  10. OpenCASCADE Conic to BSpline Curves-Parabola

    OpenCASCADE Conic to BSpline Curves-Parabola eryar@163.com Abstract. Rational Bezier Curve can repre ...