ASP.NET 3.5 MVC 架构与实战笔记6 HtmlHelper控件解析
FormExtensions类
FormExtensions类是一个静态类,定义了3种类型的扩展方法:BeginForm、BeginRouteForm、EndForm;在实际开发中,也可以使用using语句,而不需要写EndForm扩展方法。
InputExtensions类
InputExtensions类定义了5种类型的扩展方法:CheckBox,Hidden,Password,RadioButton,TextBox.
<fieldset>
<legend>CheckBoxlegend>
<label for="checkbox1">XieTilabel>
<label for="checkbox2">HeiTilabel>
<br/><br/>
<input type="submit" value="submit" />
</fieldset>
看看运行后的网页源代码吧:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
TestPage
title>head>
<body>
<div>
<form action="/Study/Index" method="post">System.Web.Mvc.Html.MvcForm
<fieldset>
<legend>¨¦¨¨??CheckBoxlegend>
<input checked="checked" id="checkBox1" name="MyCheckBox1" type="checkbox" value="true" /><input name="MyCheckBox1" type="hidden" value="false" />
<label for="checkbox1">label>
<input id="mycheckBox2" name="MyCheckBox2" type="checkbox" value="true" /><input name="MyCheckBox2" type="hidden" value="false" />
<label for="checkbox2">label>
<br/><br/>
<input type="submit" value="submit" />
fieldset>
form>
div>
body>
html>
对于每一个CheckBox控件,MVC都另外生成了一个隐藏的对应控件
<input name="MyCheckBox1" type="hidden" value="false" /> <input name="MyCheckBox2" type="hidden" value="false" /> ;
所以在控制器中检测复选框的状态,可以使用如下代码:
public ActionResult CheckBox(FormCollection formCollection)
{
b
相关文档:
文件上传界面既可以用Html的input file控件,又可以用FileUpload控件,只要将Html的input file控件加上runat="server",就会发现两者的功能完全是一模一样,上传的代码是共用的,不需要做任何改变。我想微软在将Html控件将成标准控件时应该只是多加了runat="server"吧。放入上述两者的任一控件后,添加一个标准的Button按钮 ......
在web config中 作如下配置:
<connectionStrings>
<add name="ydycon" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=|DataDirectory|ydy.mdb" providerName="System.Data.OleDb"/>
</connectionStrings>
在.net文件中应用链接 ......
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" ......
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Sy ......
第一:
private void Button1_Click( object sender, System.EventArgs e ) { Response.Redirect( Request.Url.ToString( ) ); } 第二:
private void Button2_Click( object sender, System.EventArgs e ) { Response.Write( " < script language=javascript>window.location.href=document.URL; < /script&g ......