Heim >Datenbank >MySQL-Tutorial >MVC2 中某些控件的用法

MVC2 中某些控件的用法

WBOY
WBOYOriginal
2016-06-07 15:43:361103Durchsuche

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

<p><strong>10.TextBox , Hidden </strong></p><p></p><p></p><p></p><p> a.CategoryName, new { @style = "width:300px;" })%></p><p>生成结果:   </p><p><input id="input1" name="input1" type="text" value=""></p><p><input id="input2" name="input2" style="width:300px;" type="text" value="Beverages"></p><p><input id="input3" name="input3" style="width:300px;" type="text" value=""></p><p><input id="CategoryName" name="CategoryName" style="width:300px;" type="text" value="Beverages"></p><p><strong>11.TextArea</strong></p><p></p><p> a.CategoryName, 3, 3, null)%></p><p>生成结果: </p><p><textarea cols="9" id="input5" name="input5" rows="3">Beverages</textarea></p><p><textarea cols="3" id="CategoryName" name="CategoryName" rows="3">Beverages</textarea></p><p><strong>12.CheckBox</strong></p><p></p><p></p><p>a.IsVaild, new { @class = "checkBox" })%></p><p>生成结果:   </p><p><input checked id="chk1" name="chk1" type="checkbox" value="true"></p><p><input name="chk1" type="hidden" value="false"></p><p><input class="checkBox" id="chk1" name="chk1" type="checkbox" value="true"></p><p><input name="chk1" type="hidden" value="false"></p><p><input checked class="checkBox" id="IsVaild" name="IsVaild" type="checkbox" value="true"></p><p><input name="IsVaild" type="hidden" value="false"></p><p>13.<strong>ListBox</strong></p><p></p><p> a.CategoryName, (SelectList)ViewData["Categories"])%></p><p>   生成结果:</p><p><select id="lstBox1" multiple name="lstBox1"></select></p><p><option value="1">Beverages</option></p><p><option value="2">Condiments</option></p><p><option selected value="3">Confections</option></p><p><option value="4">Dairy Products</option></p><p><option value="5">Grains/Cereals</option></p><p><option value="6">Meat/Poultry</option></p><p><option value="7">Produce</option></p><p><option value="8">Seafood</option></p><p></p><p><select id="CategoryName" multiple name="CategoryName"></select></p><p><option value="1">Beverages</option></p><p><option value="2">Condiments</option></p><p><option value="3">Confections</option></p><p><option value="4">Dairy Products</option></p><p><option value="5">Grains/Cereals</option></p><p><option value="6">Meat/Poultry</option></p><p><option value="7">Produce</option></p><p><option value="8">Seafood</option></p><p></p><p><strong>14.DropDownList</strong></p><p><strong></strong></p><p><strong> a.CategoryName, (SelectList)ViewData["Categories"], "--Select One--", new { @class = "dropdownlist" })%></strong></p><p><strong>  生成结果:</strong></p><p><strong><select id="ddl1" name="ddl1"></select></strong></p><p><strong><option value="">--Select One--</option></strong></p><p><strong><option value="1">Beverages</option></strong></p><p><strong><option value="2">Condiments</option></strong></p><p><strong><option selected value="3">Confections</option></strong></p><p><strong><option value="4">Dairy Products</option></strong></p><p><strong><option value="5">Grains/Cereals</option></strong></p><p><strong><option value="6">Meat/Poultry</option></strong></p><p><strong><option value="7">Produce</option></strong></p><p><strong><option value="8">Seafood</option></strong></p><p><strong> </strong></p><p><strong><select class="dropdownlist" id="CategoryName" name="CategoryName"></select></strong></p><p><strong><option value="">--Select One--</option></strong></p><p><strong><option value="1">Beverages</option></strong></p><p><strong><option value="2">Condiments</option></strong></p><p><strong><option value="3">Confections</option></strong></p><p><strong><option value="4">Dairy Products</option></strong></p><p><strong><option value="5">Grains/Cereals</option></strong></p><p><strong><option value="6">Meat/Poultry</option></strong></p><p><strong><option value="7">Produce</option></strong></p><p><strong><option value="8">Seafood</option></strong></p><p><strong></strong></p><p><strong>15.<strong>Partial 视图模板</strong></strong></p><p>webform里叫自定义控件。功能都是为了复用。但使用上自定义控件真的很难用好。</p><p>  看清楚了没有等号的。</p>

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中代码:

  
//引入models

       { %>
   
       


           
                |
                |
               
           
           
               
           
           
               
           
           
               
           
           
               
           
       
   
   
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn