var userAgent = navigator.userAgent,
rMsie = /(msie\s|trident.*rv:)([\w.]+)/,
rFirefox = /(firefox)\/([\w.]+)/,
rOpera = /(opera).+version\/([\w.]+)/,
rChrome = /(chrome)\/([\w.]+)/,
rSafari = /version\/([\w.]+).*(safari)/;
var browser;
var version;
var ua = userAgent.toLowerCase();
function uaMatch(ua){
var match = rMsie.exec(ua);
if(match != null){
return { browser : "IE", version : match[2] || "0" };
}
var match = rFirefox.exec(ua);
if (match != null) {
return { browser : match[1] || "", version : match[2] || "0" };
}
var match = rOpera.exec(ua);
if (match != null) {
return { browser : match[1] || "", version : match[2] || "0" };
}
var match = rChrome.exec(ua);
if (match != null) {
return { browser : match[1] || "", version : match[2] || "0" };
}
var match = rSafari.exec(ua);
if (match != null) {
return { browser : match[2] || "", version : match[1] || "0" };
}
if (match != null) {
return { browser : "", version : "0" };
}
}
// alert($("body").height());
$("#jzPro6Container").height($("body").height());
$("#swiperPage3").height($("body").height());
var browserMatch = uaMatch(userAgent.toLowerCase());
if (browserMatch.browser){
browser = browserMatch.browser;
version = browserMatch.version;
}
alert(browser+version);
alert(document.getElementById("f01").style.display);
vers=version.split(".");
if(browser=="IE" && parseInt(vers[0])<9)
document.getElementById("f01").style.display="inline";
else
document.getElementById("f02").style.display="block";
});
})
//document.write(browser+version);
</script>
参见相关文档:http://typecastexception.com/post/2014/06/22/ASPNET-Identity-20-Customizing-Users-and-Roles.aspx
一、用户角色的平台搭建
1.新建一ASP.Net WEB 应用程序(Empty)
PM> Install-Package Microsoft.AspNet.Identity.Samples -Pre
二、使用EF6.0
在文件夹下建两个类,一个是数据库连接,一个是数据库初始化。
文档SchoolContext.cs
using ContosoUniversity.Models;
usingSystem.Data.Entity;
usingSystem.Data.Entity.ModelConfiguration.Conventions;
namespaceContosoUniversity.DAL
{
publicclassSchoolContext:DbContext
{
publicSchoolContext():
base("SchoolContext"){}
publicDbSet<Student>Students{get;set;}
publicDbSet<Enrollment>Enrollments{get;set;}
public DbSet<Course>Courses{get;set;}
protectedoverridevoidOnModelCreating(DbModelBuilder modelBuilder){
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
}
文档schoolInitiallizer.cs
using System;
using System.Collections.Generic;
usingSystem.Linq;usingSystem.Web;
using System.Data.Entity;
usingContosoUniversity.Models;
namespaceContosoUniversity.DAL{
publicclassSchoolInitializer:System.Data.Entity.DropCreateDatabaseIfModelChanges<SchoolContext>{
protectedoverridevoidSeed(SchoolContext context){
var students=newList<Student>{
newStudent{FirstMidName="Carson",LastName="Alexander",EnrollmentDate=DateTime.Parse("2005-09-01")},
newStudent{FirstMidName="Meredith",LastName="Alonso",EnrollmentDate=DateTime.Parse("2002-09-01")},
newStudent{FirstMidName="Arturo",LastName="Anand",EnrollmentDate=DateTime.Parse("2003-09-01")},
newStudent{FirstMidName="Gytis",LastName="Barzdukas",EnrollmentDate=DateTime.Parse("2002-09-01")},
newStudent{FirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2002-09-01")},
newStudent{FirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2001-09-01")},
newStudent{FirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2003-09-01")},
newStudent{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2005-09-01")}
};
students.ForEach(s=> context.Students.Add(s));
context.SaveChanges();
var courses=newList<Course>{
newCourse{CourseID=1050,Title="Chemistry",Credits=3,},
newCourse{CourseID=4022,Title="Microeconomics",Credits=3,},
newCourse{CourseID=4041,Title="Macroeconomics",Credits=3,},
newCourse{CourseID=1045,Title="Calculus",Credits=4,},
newCourse{CourseID=3141,Title="Trigonometry",Credits=4,},
newCourse{CourseID=2021,Title="Composition",Credits=3,},
newCourse{CourseID=2042,Title="Literature",Credits=4,}};
courses.ForEach(s=> context.Courses.Add(s));
context.SaveChanges();
var enrollments=newList<Enrollment>{newEnrollment{StudentID=1,CourseID=1050,Grade=Grade.A},newEnrollment{StudentID=1,CourseID=4022,Grade=Grade.C},newEnrollment{StudentID=1,CourseID=4041,Grade=Grade.B},newEnrollment{StudentID=2,CourseID=1045,Grade=Grade.B},newEnrollment{StudentID=2,CourseID=3141,Grade=Grade.F},newEnrollment{StudentID=2,CourseID=2021,Grade=Grade.F},newEnrollment{StudentID=3,CourseID=1050},newEnrollment{StudentID=4,CourseID=1050,},newEnrollment{StudentID=4,CourseID=4022,Grade=Grade.F},newEnrollment{StudentID=5,CourseID=4041,Grade=Grade.C},newEnrollment{StudentID=6,CourseID=1045},newEnrollment{StudentID=7,CourseID=3141,Grade=Grade.A},};
enrollments.ForEach(s=> context.Enrollments.Add(s));
context.SaveChanges();}}}
web.config中的更改。
<entityFramework><contexts><contexttype="ContosoUniversity.DAL.SchoolContext, ContosoUniversity"><databaseInitializertype="ContosoUniversity.DAL.SchoolInitializer, ContosoUniversity"/></context></contexts><defaultConnectionFactorytype="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"><parameters><parametervalue="v11.0"/></parameters></defaultConnectionFactory><providers><providerinvariantName="System.Data.SqlClient"type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/></providers></entityFramework>
或在gloable.asxa中做如下初始化
public classMvcApplication:System.Web.HttpApplication{
protectedvoidApplication_Start(){
System.Data.Entity.Database.SetInitializer(newTriviaDatabaseInitializer());
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);B
undleConfig.RegisterBundles(BundleTable.Bundles);}}
数据库的更改:
<connectionStrings><addname="SchoolContext"connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ContosoUniversity1;Integrated Security=SSPI;"providerName="System.Data.SqlClient"/></connectionStrings>
course中外联实体的定义
using System.Collections.Generic;
usingSystem.ComponentModel.DataAnnotations.Schema;
namespaceContosoUniversity.Models{
publicclassCourse{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
publicintCourseID{get;set;}
publicstringTitle{get;set;}
publicintCredits{get;set;}
publicvirtualICollection<Enrollment>Enrollments{get;set;}
}}
分页+搜索+排序参见以下文档。
http://www.cnblogs.com/XuebinDing/archive/2012/04/05/2432798.html
ajax调用:
参见:http://eliot-jones.com/2014/09/mvc-ajax
安装Microsoft jQuery Unobtrusive Ajax,来实现mvc-ajax
如果是异步调用要用aysnc task<>来进行异步调用
如果是在局部视图中调用js
@section Scripts{
@scripts.Render();
}
@Ajax.ActionLInk{}在视图中调用 ajax.
EF数据库与模型之间的关联:
nuget
Add-Migration databasename
update-database -Force
在aspnetmvc中的ajax
参见文档
http://www.cnblogs.com/easy5weikai/p/3853817.html
http://www.2cto.com/kf/201412/357068.html
mvc5&webapi & angular
@Styles.Render("~/Content/css/gridster")
@Styles.Render("~/Content/fcpower/fcpower.TemplateDashBoard.css")
}