第一次将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. Eclipse搭建c环境(CDT)二

    Eclipse 编辑c程序环境的搭建主要为其安装CDT插件即可 Eclipse搭建CDT步骤如下: 1.首先配置好java环境,为后续运行eclipse做准备 (略) 2.下载并安装eclipse(这 ...

  2. C#与Java对比学习:数据类型、集合类、栈与队列、迭达、可变参数、枚举

    数据类型: C#:String与StringBuilder Java:String与StringBuffer 第一个不习惯是string的第一个字母必须大写了. 第二个不习惯是int得写成Intege ...

  3. node如何让一个端口同时支持https与http

    众所周知node是一个高性能的web服务器,使用它可以很简单的创建一个http或https的服务器. 比如一个很简单的http服务器: var http = require('http'); var ...

  4. Hadoop学习笔记—3.Hadoop RPC机制的使用

    一.RPC基础概念 1.1 RPC的基础概念 RPC,即Remote Procdure Call,中文名:远程过程调用: (1)它允许一台计算机程序远程调用另外一台计算机的子程序,而不用去关心底层的网 ...

  5. Unit Testing with NSubstitute

    These are the contents of my training session about unit testing, and also have some introductions a ...

  6. 企业IT管理员IE11升级指南【5】—— 不跟踪(DNT)例外

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  7. String驻留带来的危害

    原创文章转载请注明出处:@协思, http://zeeman.cnblogs.com   前段时间接手了一个项目优化工作,在同等场景下内存使用从4G降低到200M.   项目是将实体序列化成字符串存入 ...

  8. C#+OpenGL+FreeType显示3D文字(1) - 从TTF文件导出字形贴图

    C#+OpenGL+FreeType显示3D文字(1) - 从TTF文件导出字形贴图 +BIT祝威+悄悄在此留下版了个权的信息说: 最近需要用OpenGL绘制文字,这是个很费时费力的事.一般的思路就是 ...

  9. Sublime 快捷键

    语法快捷键: 后代:> 缩写:nav>ul>li <nav> <ul> <li></li> </ul> </nav& ...

  10. UGUI 之获取当前控件的高度

    当Canvas Scaler选择Constant Pixel Size 当前的分辨率会被被固定,可以用RectTransform类里面的.rect变量值获取 height或Width. 在次情况下获取 ...