MVC學習四

來源:互聯網
上載者:User

標籤:

第七節   講述了增加model中類的屬性,由於資料庫中已存在表,表中沒有存在新加的列,所以可以刪除資料庫或者在資料庫中新增一列,另可以在controller中新增一個資料庫初始化的類,並在Global.asax添加初始化資料庫的代碼

(1)@Html.DisplayNameFor(model => model.Title)是顯示列名,

(2)   @Html.DisplayFor(modelItem => item.Title)是顯示列的內容

(3)    @Html.ActionLink("Create New", "Create")是超連結,跳轉到model中的create頁面,引用的是controller中create方法;

(4) @Html.ActionLink("Edit", "Edit", new { id=item.ID })編輯頁面;

(5)  @using (Html.BeginForm()) {   @Html.ValidationSummary(true)}用於用戶端驗證,其Html.BeginForm()表示在本頁顯示

(6) <div class="editor-label">             @Html.LabelFor(model => model.Time)標籤         </div>         <div class="editor-field">             @Html.EditorFor(model => model.Time)編輯框             @Html.ValidationMessageFor(model => model.Time)驗證合法性錯誤顯示         </div>

注意點,建立MovieInitializer類時需要引用System.Data.Entity,並且DropCreateDatabaseIfModelChanges參數修改為MovieDBContext,預設為DBContext,否則會提示不能重寫seed的方法,seed的參數和DropCreateDatabaseIfModelChanges一致,當資料有增加或者刪除時,該功能會刪除資料庫再建立

第八節  講述了頁面驗證輸入資訊的有效性,首先會在用戶端驗證,驗證通過後再去服務端驗證。如果需要特殊驗證,只需要在model的類中修改添加。[DisplayFormat(DataFormatString = "{0:d}")] ,[DisplayFormat(DataFormatString = "{0:c}")]是格式化驗證。

 

第九節   講述了安全機制,一般做刪除時不是直接刪除資訊,而是先通過get方法找到所要刪除的資訊,然後顯示詳細資料到頁面,再通過使用者確認刪除post方法到刪除資訊

MVC學習四

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.