惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
P
Privacy International News Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
C
CXSECURITY Database RSS Feed - CXSecurity.com
Know Your Adversary
Know Your Adversary
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Attack and Defense Labs
Attack and Defense Labs
NISL@THU
NISL@THU
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
GbyAI
GbyAI
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Y
Y Combinator Blog
C
CERT Recently Published Vulnerability Notes
N
Netflix TechBlog - Medium
S
Security Affairs
Spread Privacy
Spread Privacy
罗磊的独立博客
腾讯CDC
MyScale Blog
MyScale Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
L
LINUX DO - 热门话题
The Cloudflare Blog
L
LangChain Blog
博客园_首页
H
Hacker News: Front Page
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
SecWiki News
SecWiki News
A
Arctic Wolf
爱范儿
爱范儿
Google Online Security Blog
Google Online Security Blog
T
Threat Research - Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
有赞技术团队
有赞技术团队
The GitHub Blog
The GitHub Blog
Cyberwarzone
Cyberwarzone
博客园 - 叶小钗
V
Visual Studio Blog
V
V2EX
T
Tailwind CSS Blog
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
MongoDB | Blog
MongoDB | Blog
D
Docker

博客园 - 王继坤

DataTable 递归 简单的程序,来实现无限级列表 结合 jquery.table.js 实现 asp.net mvc 2 简简单单做开发 使用DataContext扩展方法Find<TEntity>(TEntity obj) 遇到的问题 asp.net mvc 2 简简单单做开发 实现基本数据操作操作RepositoryController<T> asp.net mvc 2 简简单单做开发 自定义Controller基类 - 王继坤 asp.net mvc 2 简简单单做开发 自定义DropdownList控件 asp.net mvc 2 DisplayTemplates 的使用 FcDigg 源码 asp.net 3.5 linq to sql 扩展方法 linq to access 简单实现 实例demo linq to access 简单实现 asp.net mvc 随想 asp.net mvc ajax实现1 asp.net ajax fccms 小型简单个人blog源码 FCKEDITOR中文使用说明 js调用 dotfuscator.exe 采用线程生成静态页面 新的开始--- gridview 实现多字段综合查询
asp.net mvc 2 简简单单做开发 通用增删改基本操作通用页面
王继坤 · 2010-07-02 · via 博客园 - 王继坤

  asp.net mvc 2能使我们重复的工作中解脱出来,增删改等基本数据操作,都可以简单的实现。asp.net mvc 2 也借鉴不少ASP.NET Dynamic Data里的功能,通过实体类,只需要简单的操作即可以生成网站。我个人感觉,看似简单不过真正的用到开发中会遇到很多问题。自定义性太差。而asp.net mvc 2里提供了很好的方式,页面的实现可以通过,自定义字段、自定义页面来实现。mvc 2 view的查找方式  "~/Views/{1}/{0}.aspx",   "~/Views/{1}{0}.ascx","~/Views/Shared/{0}.aspx""~/Views/Shared/{0}.ascx" ,把通用的页面放到"~/Views/Shared 文件下 。为了通用实体类采 dynamic来自动实现。下面是 Index的代码,默认支持自定义查询,数据分页等基本功能。

 1 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
 2 <%@ Import Namespace="mvc.Models" %>
 3 <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
 4     Index
 5 </asp:Content>
 6 
 7 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 8  <div id="headImg">
 9         <img src="/content/adminimages/01.gif" alt="" /><%:ViewData["NavTitle"]%>
10         </div>
11         <div id="cont2">
12         <div class="form clearfix">
13    
14     <form id="form1" method="get">
15     <div id="Search" class="clearfix">
16     <%=Html.DisplayFor(m => ViewData["searchModel"], "tool","")%>   
17 
18    <li class="add">
19         <%: Html.ActionLink("添加""Add"%>
20     </li>
21     </div>
22     </form>
23    <table class="tb">
24     <% int i = 0foreach (var art in Model)
25        {
26            i++;
27            if (i == 1)
28            {  
29            %>
30   <tr  class="tbhead">
31   <%=Html.DisplayFor(m => art, "header""di")%>
32   
33     <th>操作</th>
34   </tr>
35   <%%>
36   <tr>
37   <%=Html.DisplayFor(m => art, "rows""di")%>
38   <td style="width:60px">
39    <%: Html.ActionLink("编辑""Edit"new { id = art.Id })%>  <%: Html.ActionLink("删除""Delete"new { id = art.Id }, new { onclick = "return confirm('你确定要删除吗?')" })%>
40   </td>
41   </tr>
42   <%%>
43   </table>
44     
45     <div class="page">
46      <%=ViewData["page"%>
47     </div>
48     </div>
49     </div>
50 </asp:Content>
51  

编辑页面Edit.aspx

代码

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %><asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit
</asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 
<%Html.EnableClientValidation(); %>
 
<div id="headImg">
        
<img src="/content/adminimages/01.gif" alt="" /><%:ViewData["NavTitle"]%>
        
</div>
        
<div id="cont2">
        
<div class="form clearfix">
         
<div>
        
<%: Html.ActionLink("返回列表""Index"%>
    
</div>
    
<% using (Html.BeginForm()) {%>
        
<%: Html.ValidationSummary(true%><%=Html.EditorForModel() %>
            
<class="submit" style="margin-left:100px;">
                
<input type="submit" value="保存" />
            
</p>
 
    
<% } %>
     
     
</div>
    
</div>
</asp:Content>

 添加记录页面Add.aspx

代码

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %><asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Add
</asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  
<%Html.EnableClientValidation(); %>
  
  
<div id="headImg">
        
<img src="/content/adminimages/01.gif" alt="" /><%:ViewData["NavTitle"]%>
        
</div>
        
<div id="cont2">
        
<div class="form clearfix">
      
<div>
        
<%: Html.ActionLink("返回列表""Index"%>
    
</div>
    
<% using (Html.BeginForm()) {%>
        
<%: Html.ValidationSummary(true%><%=Html.EditorForModel() %>
            
<class="submit" style="margin-left:100px;">
                
<input type="submit" value="保存" />
            
</p>
 
    
<% } %>
   
     
</div>
    
</div></asp:Content>