Html.BeginForm 与Section、Partial View 和 Child Action
该方法用于构建一个From表单的开始,他的构造方法为:
Html.BeginForm("ActionName","ControllerName",FormMethod.method)
例如:
- @using (Html.BeginForm("Index", "Home", FormMethod.Get, new { name = "nbform", id = "nbform" }))
- @using(@Html.BeginForm("ImportStu", "ProSchool", FormMethod.Post, new { enctype = "multipart/form-data" }))
- {
- <text>选择上传文件:(工作表名为“Sheet1”,“电脑号”在A1单元格。)</text>
- <input name="file" type="file" id="file" />
- <input type="submit" name="Upload" value="批量导入第一批电脑派位名册" />
- }
让请求地址不带id
- @using (Html.BeginForm("AddDIYBillOfLading", "BillOfLading", new { id ="" }, FormMethod.Post, new { name = "myform", id = "myform" }))
Section、Partial View 和 Child Action 参考:http://www.cnblogs.com/willick/p/3410855.html
右击Index方法,添加视图,编辑该视图如下:
- @model string[]
- @{
- ViewBag.Title = "Index";
- }
- @section Header {
- <div class="view">
- @foreach (string str in new [] {"Home", "List", "Edit"}) {
- @Html.ActionLink(str, str, null, new { style = "margin: 5px" })
- }
- </div>
- }
- <div class="view">
- This is a list of fruit names:
- @foreach (string name in Model) {
- <span><b>@name</b></span>
- }
- </div>
- @section Footer {
- <div class="view">
- This is the footer
- </div>
- }
编辑 /Views/Shared/_Layout.cshtml 文件如下:
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width" />
- <style type="text/css">
- div.layout { background-color: lightgray;}
- div.view { border: thin solid black; margin: 10px ;}
- </style>
- <title>@ViewBag.Title</title>
- </head>
- <body>
- @RenderSection("Header")
- <div class="layout">
- This is part of the layout
- </div>
- @RenderBody()
- <div class="layout">
- This is part of the layout
- </div>
- @RenderSection("Footer")
- <div class="layout">
- This is part of the layout
- </div>
- </body>
- </html>
section只能在当前View或它的Layout中被调用。@RenderSection方法没有找到参数指定的section会抛异常,如果不确定section是否存在,则需要指定第二个参数的值为false,如下:
- ...
- @RenderSection("scripts", false)
- ...
我们还可以通过 IsSectionDefined 方法来判断一个section是否被定义或在当前View中是否能调用得到,如:
- ...
- @if (IsSectionDefined("Footer")) {
- @RenderSection("Footer")
- } else {
- <h4>This is the default footer</h4>
- }
- ...
Html.BeginForm 与Section、Partial View 和 Child Action的更多相关文章
- [ASP.NET MVC 小牛之路]12 - Section、Partial View 和 Child Action
概括的讲,View中的内容可以分为静态和动态两部分.静态内容一般是html元素,而动态内容指的是在应用程序运行的时候动态创建的内容.给View添加动态内容的方式可归纳为下面几种: Inline cod ...
- [转][ASP.NET MVC 小牛之路]12 - Section、Partial View 和 Child Action
本文转自:http://www.cnblogs.com/willick/p/3410855.html 概括的讲,View中的内容可以分为静态和动态两部分.静态内容一般是html元素,而动态内容指的是在 ...
- ASP.NET MVC中Section、Partial View 和 Child Action(转载)
概括的讲,View中的内容可以分为静态和动态两部分.静态内容一般是html元素,而动态内容指的是在应用程序运行的时候动态创建的内容.给View添加动态内容的方式可归纳为下面几种: Inline cod ...
- ASP.NET MVC Html.Partial/Html.RenderPartial/Html.Action/Html.RenderAction区别
1. @Html.Raw() 方法输出带有html标签的字符串: <div style="margin:10px 0px 0px;border:1px;border-color:red ...
- [转]How to add a script in a partial view in MVC4?
本文转自:https://stackoverflow.com/questions/14114084/how-to-add-a-script-in-a-partial-view-in-mvc4 问题: ...
- [webgrid] – Ajax – (Reloading a Razor WebGrid after Ajax calls using a partial view)
Reloading a Razor WebGrid after Ajax calls using a partial view If you are using Razor and MVC you p ...
- MVC 之 Partial View 用法
Partial View 顾名思义就是Html代码片段,因此可以用Partial View 把部分的Html或显示逻辑包装起来,方便多次使用. Partial View 需要放在Views ...
- 视图(View)与部分视图(Partial View)之间数据传递
写ASP.NET MVC程序,我们经常需要把数据从视图(View)传递至部分视图(Partial View) 或者相反. 今天Insus.NET使用 ControllerBase.TempData 进 ...
- 截取视图某一段另存为部分视图(Partial View)
在做ASP.NET MVC后台管理程序时,根据程序需要,Isus.NET需要实现一个功能,就是动态截取视图某一段另存为部分视图Partial View. 思路为在视图中,使用jQury的程序截图以及P ...
随机推荐
- 利用ICSharpCode进行压缩和解压缩
说说我利用ICSharpCode进行压缩和解压缩的一些自己的一下实践过程 1:组件下载地址 参考文章:C#使用ICSharpCode.SharpZipLib.dll压缩文件夹和文件 2: 文件类 // ...
- 在16aspx.com上下了一个.net程序,怎么修改它的默认登录名和密码?
正常应该有个login.aspx文件,找到登入按钮事件,查看验证用户名密码事件,这个验证就有去搜索用户表,然后在这个用户表修改用户名密码就行了.不排除其他表有用用户名关联
- 大数据技术之_16_Scala学习_09_函数式编程-高级
第十三章 函数式编程-高级13.1 偏函数(partial function)13.1.1 提出一个需求,引出思考13.1.2 解决方式-filter + map 返回新的集合13.1.3 解决方式- ...
- FZU -2212 Super Mobile Charger(水题)
Problem 2212 Super Mobile Charger Accept: 1033 Submit: 1944Time Limit: 1000 mSec Memory Limit ...
- jcl sort comp3 to 表示型
Lets say your packed data is at 10th column and is of length 6, S9(4)V99 You could try the following ...
- docker环境准备及理论
1.预热 内核运行在内核空间,进程运行在用户空间,linux进程特性:父进程负责子进程的创建和回收,白发人送黑发人.容器就是为了保护它里面的内容物,不受其他容器干扰,也不去干扰其他容器.容器让进程认为 ...
- POJ3261 Milk Patterns(二分+后缀数组)
题目求最长的重复k次可重叠子串. 与POJ1743同理. 二分枚举ans判定是否成立 height分组,如果大于等于ans的组里的个数大于等于k-1,这个ans就可行 #include<cstd ...
- jsp笔记2(编译指令与动作指令)
一.jsp的编译指令是通知jsp引擎的消息,不会生成输出. jsp的3个编译指令: page:针对当前页面的指令 include:包含另一个页面的指令 taglib:用于定义和访问自定义标签 ...
- String&&StringBuilder&&StringBuffer
在java中提供三个操作字符串的类:String,StringBuilder,StringBuffer (1)什么是字符串:多个字符的集合 (2)String 是内容不可变的字符串.(底层使用了一个不 ...
- ASIHTTPRequest框架使用总结系列之阿堂教程1(安装配置篇
在前年,阿堂在<IOS开发系列之阿堂教程:玩转IPhone客户端和Web服务端交互(客户端)实践>一文中,对于ASIHTTPRequest框架有过一些介简单绍,具体链接地址见http:// ...