zoukankan      html  css  js  c++  java
  • 轻松学MVC4.0–3 删除用户功能

    在上一篇中,我们创建了用户列表页面。 现在,我们将用户列表功能,加入到菜单中。打开 Views\Shared\_Layout.cshtml,找到菜单部分,加入用户列表菜单项:
    mx371AB

    保存后,右键点击项目文件,弹出菜单中选 “在浏览器中查看”:

    mx39D6C

    如果未登录点击Users, 会跳转到登录页面,这是因为在其Controller类AccountController中,加入了一个Attribute: [Authorize]

    mx33CA7

    打开上一篇中创建的Views\Account\Index.cshtml,  修改 Delete 链接,增加一个确认删除的提示框:
    mx3B965

    打开AccountController,增加一个删除的Action:

    mx35A07

     

    下面是UserProfile.Delete()的代码:
    mx341A2

    至此删除功能已完成。

    本篇知识点:
    1) 验证用户才能访问的页面,在Controller类或方法上加attribute:  [Authorize]

    2 )  给HTML控件加属性时,如果需要传属性对象,一般用 new { @attrName=””}的形式。

    3 ) 在Action中跳转到其它View,用 return View(“ViewName”,modelObject); 的形式。当然,关于跳转还有一些其它方式。

    4)执行不返回结果集的SQL语句,用 context.Database.ExcuteSqlCommand()

  • 相关阅读:
    oracle学习13
    oracle学习12
    oracle学习11
    oracle学习10
    CodeForces
    CodeForces
    UVA
    poj3320 Jessica's Reading Problem
    poj2456 Aggressive cows
    jQuery 鼠标滚轮插件 mousewheel
  • 原文地址:https://www.cnblogs.com/ybst/p/2747997.html
Copyright © 2011-2022 走看看