asp.net MVC2 初探二

本文介绍ASP.NET MVC项目的发布步骤,包括设置DLL文件、网站配置等,并提供了一个使用LINQ进行数据库查询的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这一节我们看如何发布Asp.net MVC
在项目的引用中设置上面三个dll的copy local为true,然后在项目上点击右键publish,publish到一个目录下。这个和一般的wenForm页面一样。然后进行网站配置
 
确保这块是4.0,当然根据你装的.net版本,点击主目录
确保aspnet_isapi.dll要在目录中,如下
还有启用下面的选项
运行网站,如下,成功了。
下面是一个LINQ查询的示例
InBlock.gifusing System; 
InBlock.gifusing System.Collections.Generic; 
InBlock.gifusing System.Linq; 
InBlock.gifusing System.Web; 
InBlock.gifusing System.Web.UI; 
InBlock.gifusing System.Web.UI.WebControls; 
InBlock.gif 
InBlock.gifpublic partial class _Default : System.Web.UI.Page 
InBlock.gif
InBlock.gif        protected void Page_Load(object sender, EventArgs e) 
InBlock.gif        { 
InBlock.gif                if (!IsPostBack) 
InBlock.gif                { 
InBlock.gif                        DataClassesDataContext dc = new DataClassesDataContext(System.Configuration.ConfigurationManager.ConnectionStrings["MoviesConnectionString"].ToString()); 
InBlock.gif                        this.GridView1.DataSource = dc.Movies; 
InBlock.gif                        this.GridView1.DataBind(); 
InBlock.gif                        this.BindDropDowList(); 
InBlock.gif                } 
InBlock.gif                
InBlock.gif        } 
InBlock.gif        protected void Button1_Click(object sender, EventArgs e) 
InBlock.gif        { 
InBlock.gif                IQueryable<Movy> Iquery=null
InBlock.gif                int id = int.Parse(DropDownList1.SelectedValue); 
InBlock.gif                switch (id) 
InBlock.gif                { 
InBlock.gif                        case -1: 
InBlock.gif                                Iquery = from movie in new DataClassesDataContext().Movies select movie; 
InBlock.gif                                break
InBlock.gif                        default
InBlock.gif                                Iquery = from movie in new DataClassesDataContext().Movies 
InBlock.gif                                                 where movie.ID == id 
InBlock.gif                                                 select movie; 
InBlock.gif                                break
InBlock.gif                } 
InBlock.gif                this.GridView1.DataSource = Iquery; 
InBlock.gif                this.GridView1.DataBind(); 
InBlock.gif        } 
InBlock.gif 
InBlock.gif        protected void BindDropDowList() 
InBlock.gif        { 
InBlock.gif                DataClassesDataContext dc = new DataClassesDataContext(System.Configuration.ConfigurationManager.ConnectionStrings["MoviesConnectionString"].ToString()); 
InBlock.gif                this.DropDownList1.DataSource = dc.Movies.ToList(); 
InBlock.gif                this.DropDownList1.DataTextField = "Movie_Name"
InBlock.gif                this.DropDownList1.DataValueField = "Id"
InBlock.gif                this.DropDownList1.DataBind(); 
InBlock.gif                this.DropDownList1.Items.Insert(0, new ListItem("全部""-1")); 
InBlock.gif        } 
InBlock.gif        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
InBlock.gif        { 
InBlock.gif                if (e.Row.RowType == DataControlRowType.DataRow) 
InBlock.gif                { 
InBlock.gif                        e.Row.Attributes.Add("onMouseOver""SetNewColor(this);"); 
InBlock.gif                        e.Row.Attributes.Add("onMouseOut""SetOldColor(this);"); 
InBlock.gif                }        
InBlock.gif        } 
InBlock.gif
运行结果如下


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值