Asp.net MVC3 Razor语法小记
1.在MVC View中使用 三元运算符的方式:@(bool?"":"")
2.在@{}中输出一行:@:<html>.如果这一行的上下文在程序代码中则用:@Html.Raw(string.Format(""));而不是Html.Raw();
3.Radio默认选中: @Html.RadioButtonFor(m => m.BookType, 0, new { @checked="checked"})小学
4.DropDownList添加非数据库数据项:
IEnumerable<SelectListItem> ColumnList = from a in Company.Column.ToList() where a.parentID==0 select new SelectListItem { Value = a.ColumnID.ToString(), Text = a.name }; List<SelectListItem> Items = new List<SelectListItem>(); Items.Add( new SelectListItem { Value = "0" , Text = "一级栏目" }); Items.AddRange(ColumnList); ViewBag.ColumnList = Items; 。。。。 ***添加静态数据项: @Html.DropDownListFor(model => model.GroupCategoryID,new SelectListItem[] { new SelectListItem { Text = "小学", Value = "1" }, new SelectListItem { Text = "中学", Value = "2" } }) 5.在页面中输出javascript变量值: <script language="JavaScript" type="text/javascript"> |