標籤:ace using resource contain mod 項目 執行個體 lstat 地址欄
修改代碼,使得發布ReleaseDate看上去更好。開啟Balls \ Ball.cs檔案
using System;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
namespace Balls.Models
{
public class Ball{
public int ID { get; set; }
public string one1{ get; set; }
public string one2 { get; set; }
public string one3{ get; set; }
}
public class BallsDBContext : DbContext
{
public DbSet<Ball> Team { get; set; }
}
}
在瀏覽器地址欄裡追加/Balls, 瀏覽到Balls頁面。並進入編輯(Edit)頁面。
MapRoute方法是使用HTTP請求路由尋找到正確的控制器(controller)和行動方法,並提供了可選ID的參數。
MapRoute方法也被用於通過HtmlHelpers如ActionLink的控制器,操作方法及任何路由資料,以產生URL。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Balls", action ="Index",
id = UrlParameter.Optional }
);
}
處理POST 請求
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResultone1([Bind(Include="ID,Shenglv,ReleaseDate,Age,Rongyu")] Movie movie)
{
if (ModelState.IsValid)
{
db.Entry(Ball).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(Ball);
}
接收form所post的資料,並轉換所接收的Balls請求資料從而建立一個Ball對象。
ModelState.IsValid方法用於驗證提交的表單資料是否可用於修改(編輯或更新)一個Ball對象。
如果資料是有效資料,將儲存到資料庫的Ball集合(BallDBContext 執行個體)。
通過調用BallDBContext的SaveChanges方法,新的資料會被儲存到資料庫。
資料儲存之後,代碼會把使用者重新導向到BallsController類的Index操作方法,頁面將顯示列表,同時包括剛剛所做的更新。
添加搜尋
public ActionResult Index(string BallGenre, string searchString)
{
var GenreLst = new List<string>();
var GenreQry = from d in db.Balls
orderby d.Genre
select d.Genre;
GenreLst.AddRange(GenreQry.Distinct());
ViewBag.movieGenre = new SelectList(GenreLst);
var Balls = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
Balls = Balls.Where(s =>s.Title.Contains(searchString));
}
if (!string.IsNullOrEmpty(BallGenre))
{
Balls = Balls.Where(x => x.Genre == BallGenre);
}
return View(Balls);
方法的驗證主要是對輸入的得分情況及得分上限的驗證
本次的項目驗證是對排球每一局的得分進行簡單的驗證
MVC開發之排球計分(七)驗證編輯方法