这一节我们看如何发布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);");
}
}
}
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,如需转载请自行联系原作者