本文共 1014 字,大约阅读时间需要 3 分钟。
1、MVC5 View视图中创建带样式超链接
@Html.ActionLink("action名","controller名",new { id=item.ID },new{style="color:red",@class="css样式名"})
@Html.LabelFor(model => model.Genre, new { @class = "control-label" })@Html.ValidationMessageFor(model => model.Genre, null, new { @class = "help-inline" })
2、Model中字段的显示设置及类型指定
添加引用
using System.ComponentModel.DataAnnotations;
[Display(Name = "发布日期")] [DataType(DataType.Date)]public DateTime ReleaseDate { get; set; }
Display 特性指定了显示的字段名(本例中“发布日期”替换了“ReleaseDate”)。
DataType 特性指定了数据类型,在本例中它是日期类型,因此存储在该字段的时间信息将不会显示出来。
3、
[HttpPost][ValidateAntiForgeryToken]public ActionResult Edit(Movie movie){ if (ModelState.IsValid) { db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(movie);}HttpPost特性指定只有POST请求才能调用这个Edit方法。HttpGet是默认值,无需指定。ValidateAntiForgeryToken 这个特性用来阻止伪造的请求,它和视图(Views\Movies\Edit.cshtml)中的
@Html.AntiForgeryToken() 是成对出现的。
@using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true)}
转载地址:http://yuudm.baihongyu.com/