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 ...
随机推荐
- mydumper备份
1.安装工作 cd /usr/local/softwareyum install -y glib2-devel zlib-devel pcre-develwget https://launchpad ...
- [BZOJ1854][SCOI2010]游戏 二分图最大匹
1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 5316 Solved: 2128[Submit][Status] ...
- 找出数字数组中最大的元素(使用Math.max函数)
从汤姆大叔的博客里看到了6个基础题目:本篇是第1题 - 找出数字数组中最大的元素(使用Match.max函数) 从要求上来看,不能将数组sort.不能遍历.只能使用Math.max,所以只能从java ...
- Netty源码学习(零)前言
本系列文章将介绍Netty的工作机制,以及分析Netty的主要源码. 基于的版本是4.1.15.Final(2017.08.24发布) 水平有限,如有谬误请留言指正 参考资料 the_flash的简书 ...
- (28)C#委托,匿名函数,lambda表达式,事件
一.委托 委托是一种用于封装命名和匿名方法的引用类型. 把方法当参数,传给另一个方法(这么说好理解,但实际上方法不能当参数,传入的是委托类型),委托是一种引用类型,委托里包含很多方法的引用 创建的方法 ...
- 第一讲work(axe)
1,Dao package com.songyan.Dao; public interface Axe { public void chop(); } package com.songyan.Dao; ...
- UITableView中的dequeueReusableCellWithIdentifier的方法
在使用UITableView控件的时候,datasource的代理方法经常会使用到下面的方法来加载UITableView的数据显示 - (UITableViewCell *)tableView:(UI ...
- Android开发之onCreate
最近看了一些开发人员做的APP开发,虽然都实现了比较完美的功能,不过很多地方很是牵强!我觉得:作为一个合格软件工程师,最重要的不是你写过多少代码,而是你研究过多少代码!所以,我更倡导多研究系统原本定制 ...
- 【转】三种方式在C++中调用matlab
C/C++调用Matlab 在工程实践中,C/C++调用Matlab 的方法主要有调用Matlab 计算引擎.包含m 文件转 换的C/C++文件,以及调用m文件生成的DLL 文件. 1 利用Mat ...
- 【Git】windows上git命令中文乱码的问题
windows上git命令中文乱码的问题解决 1.打开git bash快捷方式启动 2.右键 options 3.进入text选项卡,选中中文 和UTF-8 4.应用 测试[中文正常显示] 尝试打开文 ...