asp.net MVC2 初探二

简介:
这一节我们看如何发布Asp.net MVC
在项目的引用中设置上面三个dll的copy local为true,然后在项目上点击右键publish,publish到一个目录下。这个和一般的wenForm页面一样。然后进行网站配置
 
确保这块是4.0,当然根据你装的.net版本,点击主目录
确保aspnet_isapi.dll要在目录中,如下
还有启用下面的选项
运行网站,如下,成功了。
下面是一个LINQ查询的示例
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
 
public partial  class _Default : System.Web.UI.Page 

         protected  void Page_Load( object sender, EventArgs e) 
        { 
                 if (!IsPostBack) 
                { 
                        DataClassesDataContext dc =  new DataClassesDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[ "MoviesConnectionString"].ToString()); 
                         this.GridView1.DataSource = dc.Movies; 
                         this.GridView1.DataBind(); 
                         this.BindDropDowList(); 
                } 
                
        } 
         protected  void Button1_Click( object sender, EventArgs e) 
        { 
                IQueryable<Movy> Iquery= null
                 int id =  int.Parse(DropDownList1.SelectedValue); 
                 switch (id) 
                { 
                         case -1: 
                                Iquery = from movie  in  new DataClassesDataContext().Movies select movie; 
                                 break
                         default
                                Iquery = from movie  in  new DataClassesDataContext().Movies 
                                                 where movie.ID == id 
                                                 select movie; 
                                 break
                } 
                 this.GridView1.DataSource = Iquery; 
                 this.GridView1.DataBind(); 
        } 
 
         protected  void BindDropDowList() 
        { 
                DataClassesDataContext dc =  new DataClassesDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[ "MoviesConnectionString"].ToString()); 
                 this.DropDownList1.DataSource = dc.Movies.ToList(); 
                 this.DropDownList1.DataTextField =  "Movie_Name"
                 this.DropDownList1.DataValueField =  "Id"
                 this.DropDownList1.DataBind(); 
                 this.DropDownList1.Items.Insert(0,  new ListItem( "全部""-1")); 
        } 
         protected  void GridView1_RowDataBound( object sender, GridViewRowEventArgs e) 
        { 
                 if (e.Row.RowType == DataControlRowType.DataRow) 
                { 
                        e.Row.Attributes.Add( "onMouseOver""SetNewColor(this);"); 
                        e.Row.Attributes.Add( "onMouseOut""SetOldColor(this);"); 
                }        
        } 

运行结果如下


本文转自 BruceAndLee 51CTO博客,原文链接:http://blog.51cto.com/leelei/317871,如需转载请自行联系原作者

目录
打赏
0
0
0
0
265
分享
相关文章
一款基于 .NET MVC 框架开发、功能全面的MES系统
一款基于 .NET MVC 框架开发、功能全面的MES系统
ASP.NET MVC 教程
ASP.NET 是一个使用 HTML、CSS、JavaScript 和服务器脚本创建网页和网站的开发框架。
82 7
ASP.NET MVC 迅速集成 SignalR
ASP.NET MVC 迅速集成 SignalR
120 0
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
86 0
|
6月前
|
Asp.Net Core 使用X.PagedList.Mvc.Core分页 & 搜索
Asp.Net Core 使用X.PagedList.Mvc.Core分页 & 搜索
195 0
JavaScript云LIS系统源码ASP.NET CORE 3.1 MVC + SQLserver + Redis医院实验室信息系统源码 医院云LIS系统源码
实验室信息系统(Laboratory Information System,缩写LIS)是一类用来处理实验室过程信息的软件,云LIS系统围绕临床,云LIS系统将与云HIS系统建立起高度的业务整合,以体现“以病人为中心”的设计理念,优化就诊流程,方便患者就医。
97 0

热门文章

最新文章