这篇文章主要介绍了MVC3中辅助方法怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:空间域名、虚拟主机、营销软件、网站建设、周宁网站维护、网站推广。
1,
@Html.TextBox("txt", "hello", new { style = "width:1000px;height:1000px;" })生成标签:
2,
特殊属性(class:c#保留关键字)
@Html.TextBox("txt", "hello", new { style = "width:1000px;height:1000px;",@class="aa" })生成标签:
3,
带连接字符的属性(例如:data_result)
@Html.TextArea("text", "hello", new { data_result ="data"})生成标签:
4,
@using (Html.BeginForm())
{
}生成标签:
==================添加输入元素
----@Html.TextBox
@Html.TextBox("Title", string.Empty)
//单行输入生成标签:
----@Html.TextArea
@Html.TextArea("Title", string.Empty)
//多行输入生成标签:
----@Html.Label
@Html.Label("Title","请输入:")生成标签:
---- @Html.DropDownList
控制器代码:
public ActionResult Create2()
{
//单选 集合 ,值字段,文本字段,选定的值
ViewBag.Genre = new SelectList(db.Genres, "GenreId", "Name",1);
return View();
}视图代码:
@Html.DropDownList("Genre",string.Empty) 
---- @Html.ListBox(可以多项选择)
@{
List listbox = new List();
listbox.Add("a");
listbox.Add("b");
listbox.Add("c");
}
@Html.ListBox("listitem", new SelectList(listbox,"a")) 
控制器代码:
//public ActionResult Create2()
{
//单选 集合 ,值字段,文本字段,选定的值
ViewBag.Genre = new SelectList(db.Genres, "GenreId", "Name",1);
//多选
ViewBag.Genre2 = new MultiSelectList(db.Genres, "GenreId", "Name", new List() { "1", "2" });
return View();
} 视图代码:
@Html.ListBox("Genre")
@Html.ListBox("Genre2")
----@Html.ValidationMessage()
控制器代码:
public ActionResult Create3()
{
return View();
}
[HttpPost]
public ActionResult Create3(string text)
{
if (string.IsNullOrEmpty(text))
{
ModelState.AddModelError("text", "错误");
return View();
}
else
{
return RedirectToAction("Index");
}
}视图代码:
@{
ViewBag.Title = "Create3";
}
Create3
@using (Html.BeginForm())
{

感谢你能够认真阅读完这篇文章,希望小编分享的“MVC3中辅助方法怎么用”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!