zoukankan      html  css  js  c++  java
  • MVC学习四

    第七节   讲述了增加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方法到删除信息

  • 相关阅读:
    Soldier and Number Game素数筛
    HDU1501Zipper字符串的dfs
    HDU1285 确定比赛名次 拓扑排序模板题
    HDU1595 find the longest of the shortest dijkstra+记录路径
    HDU1556 Color the ball 前缀和/线段树/树状数组
    Function Run Fun递归+细节处理
    数学公式
    日常 java+雅思+训练题1
    HDU1423Greatest Common Increasing Subsequence
    HDU1595find the longest of the shortestdijkstra+记录路径
  • 原文地址:https://www.cnblogs.com/handsomer/p/4228479.html
Copyright © 2011-2022 走看看