第一次将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. 通过远程 http API 来控制 lnmp 环境的重启perl脚本

    #!/usr/bin/perl use DBD::mysql; use strict; use warnings; use DBI; use utf8; binmode(STDOUT, ':encod ...

  2. 一个基于Orchard的开源CRM --coevery简介

    Coevery是开源的.NET Web平台项目,力争打造一个开放而鲁棒的CRM系统,采用Orchard架构,并使用AngularJS改善页面体验.作为一个后发优势的CRM 产品,Coevery 具有一 ...

  3. 关于MongoDB你需要知道的几件事

    Henrique Lobo Weissmann是一位来自于巴西的软件开发者,他是itexto公司的联合创始人,这是一家咨询公司.近日,Henrique在博客上撰文谈到了关于MongoDB的一些内容,其 ...

  4. Unity3D游戏开发初探—3.初步了解U3D物理引擎

    一.什么是物理引擎? 四个世纪前,物理学家牛顿发现了万有引力,并延伸出三大牛顿定理,为之后的物理学界的发展奠定了强大的理论基础.牛顿有句话是这么说的:“如果说我看得比较远的话,那是因为我站在巨人的肩膀 ...

  5. clojure基础入门(一)

    最近在看storm的源码,就学习分享下clojure语法. 阅读目录: 概述 变量 运算符 流程控制 总结 概述 clojure是一种运行在JVM上的Lisp方言,属于函数式编程范式,它和java可以 ...

  6. 企业IT管理员IE11升级指南【7】—— Win7和Win8.1上的IE11功能对比

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

  7. 七天学会ASP.NET MVC (三)——ASP.Net MVC 数据处理

    第三天我们将学习Asp.Net中数据处理功能,了解数据访问层,EF,以及EF中常用的代码实现方式,创建数据访问层和数据入口,处理Post数据,以及数据验证等功能. 系列文章 七天学会ASP.NET M ...

  8. 前端MVC框架Backbone 1.1.0源码分析(二) - 模型

    模型是什么? Models are the heart of any JavaScript application, containing the interactive data as well a ...

  9. Make Helix Curve in OpenCASCADE

    Make Helix Curve in OpenCASCADE eryar@163.com Abstract. OpenCASCADE does not provide helix curve dir ...

  10. js学习内容的整理

    1.jquery动态添加Table中的一行 function addTableRow(tableId){var html = '<tr>\ ......\ </tr>" ...