(1)Html.Encode
<%= Html.Encode(ViewData["Message"]) %>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
定义和用法
HTMLEncode 方法对一段指定的字符串应用 HTML 编码。
语法
Server.HTMLEncode(string)参数 描述
string 必需。要编码的字符串。
实例
脚本:
<%
response.write(Server.HTMLEncode("The image tag:
"))
%>输出:
The image tag: <img>浏览器的输出:
The image tag: <img>
(2)Html.RenderPartial
<% Html.RenderPartial("LoginUserControl"); %>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->Html.RenderPartial("viewName");
我猜就是相当于一个include
把一个用户控件包含在当前面
"viewName" 当然就是一个用户控件了
但是这个用户控件貌似必须继承与System.Mvc.ViewUserControl这个类
而并非普通的用户控件
它的效果竟然和下面的代码一样
<uc1:Header ID="viewName" runat="server" />
(3)Html.ActionLink
<%= Html.ActionLink("Home", "Index", "Home")%>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><%= Html.ActionLink( string linkText, string actionName, string controllerName) %>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><%= Html.ActionLink("编辑", "EditCategory", new { id = category.Id })%>
<%= Html.ActionLink("删除", "DelCategory", new { id = category.Id }, new { onclick = "return confirm('你确定要删除该随笔?')" })%>
(4)<%= Html.TextBox("username") %>
<%= Html.Password("password") %>
<%= Html.CheckBox("rememberMe") %>

Code
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><input id="username" name="username" type="text" value="" />
<input id="password" name="password" type="password" value="" />
<input id="rememberMe" name="rememberMe" type="checkbox" value="true" />
(5) Html.ValidationSummary()
<%= Html.ValidationSummary() %>
<%= Html.ValidationMessage("username") %>
例如,我们可以更新我们的视图,在文本框的右方使用Html.ValidationMessage()辅助方法,象这样
当页面因错而显示时,错误消息就会显示在有问题的控件域之后:
Html.ValidationMessage() 方法还有一个重载的版本,接受第二个参数,允许视图指定要显示的替换文字:
常见的一个用例是,在输入控件域后面输出 * 字符,然后将新的Html.ValidationSummary()辅助方法(也是第五个预览版中新加的)加到页面的顶部,来列出所有的错误消息:
Html.ValidationSummary()辅助方法然后就会用
显示出ModelState集合中的所有错误消息,以及 * 和 红边框会表示每个有问题的输入控件元素:
注意,我们完全不用改动ProductsController类就取得了如此效果。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-545465/
,如需转载,请注明出处,否则将追究法律责任。