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 ...
随机推荐
- ASPOSE.WORD 另存为HTML
var fi = new FileInfo(Environment.CurrentDirectory + "\\AE9302C0-AE48-4F4B-8489-6A428D9163C9_AL ...
- Laravel实现用户名或密码登录
要实现用户名或密码登录,这就要用到强大的filter_var函数 该函数通过指定的过滤器过滤变量,可以判断输入值是否是数字.是否是字符串.是否是邮箱.是否是IP等等,不用写麻烦的正则 $type = ...
- ()C# DataRow
判断某列是否存在,返回bool dr.Table.Columns.Contains("水分含量")
- Out of Sorts II
问题 E: Out of Sorts II 时间限制: 1 Sec 内存限制: 128 MB提交: 68 解决: 4[提交] [状态] [讨论版] [命题人:] 题目描述 Keeping an e ...
- Ubuntu 16.04网络管理工具NetworkManager无法使用nm-tool的问题
说明: 1.在Ubuntu中网络设置分两类,一个是GUI配置工具NetworkManager,另一个是命令行的配置,两者只能共存一个,也就是说其中一个设置之后另一个就会失效: 2.NetworkMan ...
- JAVA常见算法题(十三)
package com.xiaowu.demo; /** * 企业发放的奖金根据利润提成: 利润(I)低于或等于10万元时,奖金可提10%: 利润高于10万元,低于20万元时,低于10万元的部分按10 ...
- selenium 定位元素方式大全
starts-with 顾名思义,匹配一个属性开始位置的关键字 contains 匹配一个属性值中包含的字符串 text() 匹配的是显示文本信息,此处也可以用来做定位用 eg //input[sta ...
- Makefile之文件搜索
Makefile之文件搜索 1.Makefile 文件中的"VPATH"变量 如果没有指明这个变量,make只会在当前目录下查找依赖文件和目标文件: 如果定义了这个变量,make会 ...
- 模式识别hw2-------基于matconvnet,用CNN实现人脸图片性别识别
主要来源模式识别课程大作业,本文首先感谢当初的助教和一起完毕作业的队友 matconvnet在matlab下封装了CNN常见算法,网址http://www.vlfeat.org/matconvnet/ ...
- C#设计模式---观察者模式简单例子
在开发过程中经常遇到一个模块中的 一个方法调用了其他模块中相关的方法 比如说在一个系统中,如果出现了错误,就调用专门进行错误处理的模块中的方法进行错误处理 而因为错误处理的操作有很多,所以将这些具体的 ...