时间:2021-07-01 10:21:17 帮助过:31人阅读
10.TextBox , Hidden %=Html.TextBox(input1) % %=Html.TextBox(input2,Model.CategoryName,new{ @style = width:300px; }) % %=Html.TextBox(input3, ViewData[Name],new{ @style = width:300px; }) % %=Html.TextBoxFor(a = a.CategoryName, new { @style
10.TextBox , Hidden
<%=Html.TextBox("input1") %>
<%=Html.TextBox("input2",Model.CategoryName,new{ @style = "width:300px;" }) %>
<%=Html.TextBox("input3", ViewData["Name"],new{ @style = "width:300px;" }) %>
<%=Html.TextBoxFor(a => a.CategoryName, new { @style = "width:300px;" })%>
生成结果:
11.TextArea
<%=Html.TextArea("input5", Model.CategoryName, 3, 9,null)%>
<%=Html.TextAreaFor(a => a.CategoryName, 3, 3, null)%>
生成结果:
12.CheckBox
<%=Html.CheckBox("chk1",true) %>
<%=Html.CheckBox("chk1", new { @class="checkBox"}) %>
<%=Html.CheckBoxFor(a =>a.IsVaild, new { @class = "checkBox" })%>
生成结果:
13.ListBox
<%=Html.ListBox("lstBox1",(SelectList)ViewData["Categories"])%>
<%=Html.ListBoxFor(a => a.CategoryName, (SelectList)ViewData["Categories"])%>
生成结果:
14.DropDownList
<%= Html.DropDownList("ddl1", (SelectList)ViewData["Categories"], "--Select One--")%>
<%=Html.DropDownListFor(a => a.CategoryName, (SelectList)ViewData["Categories"], "--Select One--", new { @class = "dropdownlist" })%>
生成结果:
15.Partial 视图模板
webform里叫自定义控件。功能都是为了复用。但使用上自定义控件真的很难用好。
<% Html.RenderPartial("DinnerForm"); %> 看清楚了没有等号的。
16 mvc中的模糊查询和精确查询:
var talk = dbTalk.talk.Where(m => m.name.IndexOf(keyWord)>=0);//模糊查询
dbTalk.talk.Where(m => m.name.Equals(keyWord) == true);//精确查询
应用:
在控制器中的Action:
public ActionResult search()
{
string keyWord = Request.Form["keyWord"];
var talk = dbTalk.talk.Where(m => m.name.IndexOf(keyWord)>=0);//dbTalk.talk.Where(m => m.name.Equals(keyWord) == true);//
if (talk == null)
{ ViewData["error"] = "未找到相关信息!"; }
else
{ ViewData["error"] = "Yes!";}
ViewData.Model = talk; //视图页面数据
return View();
}
view中代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="MvcApplication1.Models" %>//引入models
<% foreach (talk item in (IEnumerable)ViewData.Model)//转换为你想要的类型(ViewData.Model为控制器中传过来的数据)
{ %>