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 ...
随机推荐
- hdu 1856(hash+启发式并查集)
More is better Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others) ...
- Android studio配置使debug签名和release签名一致
在module的build.gradle中添加 android { //重要部分 signingConfigs { release { keyAlias 'jxt' keyPassword '1234 ...
- Educational Codeforces Round 31 B. Japanese Crosswords Strike Back【暴力】
B. Japanese Crosswords Strike Back time limit per test 1 second memory limit per test 256 megabytes ...
- docker环境准备及理论
1.预热 内核运行在内核空间,进程运行在用户空间,linux进程特性:父进程负责子进程的创建和回收,白发人送黑发人.容器就是为了保护它里面的内容物,不受其他容器干扰,也不去干扰其他容器.容器让进程认为 ...
- Editing 2011-2012 ACM-ICPC Northeastern European Regional Contest (NEERC 11)
NEERC 11 *wiki链接[[https://acm.ecnu.edu.cn/wiki/index.php?title=2011-2012_ACM-ICPC_Northeastern_Europ ...
- [Contest20180418]数学竞赛
题意:初始时$x=0$(长度),当$x$为长度时,你可以把$x$变成$\sin^{-1}x,\cos^{-1}x,\tan^{-1}x$之一($x$变为角度),若$x$为角度,你可以把$x$变成$\s ...
- 1.13(java学习笔记)异常机制
异常不同于错误,它是程序运行时产生的未知问题. 如果把程序比喻成一辆汽车,那么汽车开着开着突然前面出现了一个大石头挡住了路,这就叫异常. 那么出现了这个异常我们需要去处理,比如打电话给公路管理局,让它 ...
- 三. Java类与对象9. 源文件的声明规则
当在一个源文件中定义多个类,并且还有import语句和package语句时,要特别注意这些规则: 一个源文件中只能有一个public类. 一个源文件可以有多个非public类. 源文件的名称应该和pu ...
- strace 使用案例
http://www.cnblogs.com/lixigang/articles/5512527.html
- 【Linux】CentOS7上安装搜狗输入法
找到一篇资料,提供安装搜狗输入法的方法,在http://www.cnblogs.com/Yiutto/p/6204085.html[也是本文的参考原地址] 请大家自行下载fcitx.tar.gz 1. ...