Loading

上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 46 下一页
摘要: 开始之前,先补习一下params关键字的用法:paramsparams关键字可以指定在参数数目可变处采用参数的方法参数。在方法声明中的params关键字之后不允许任何其他参数,并且在方法声明中只允许一个params关键字首先自定义View 1 public class DebugView:IView 2 { 3 public void Render(ViewContext viewContext, System.IO.TextWriter writer) 4 { 5 Write(writer, "-----RouteData--... 阅读全文
posted @ 2013-04-04 13:10 青岛欧姆网络科技 阅读(368) 评论(0) 推荐(0)
摘要: MVC 3 允许创建自己的视图引擎而不使用自带的Razor视图或者APSX视图。下面就介绍一下如何创建自定义的视图引擎。首先,View Engine 继承于 IViewEngine接口。IViewEngine接口的定义如下:1 public interface IViewEngine {2 ViewEngineResult FindView(ControllerContext controllerContext, string viewName,3 string masterName, bool useCache);4 ViewEngineResult FindPartialView(Cont 阅读全文
posted @ 2013-04-04 12:29 青岛欧姆网络科技 阅读(1180) 评论(0) 推荐(0)
摘要: 原因在于没有设置WFC支持Http行为解决方法是将webconfig文件改成下面的格式:<?xml version="1.0"?><configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <protocolMapping> <add scheme="http&quo 阅读全文
posted @ 2013-04-03 15:55 青岛欧姆网络科技 阅读(2675) 评论(0) 推荐(0)
摘要: View Code var intList = new int[] { 1, 2, 3, 4, 5, -1, -2 };Console.WriteLine("Where");foreach (var i in intList.Where(x => x <= 3)) Console.WriteLine(i);Console.WriteLine("TakeWhile");foreach (var i in intList.TakeWhile(x => x <= 3)) Console.WriteLine(i);Where123-1-2 阅读全文
posted @ 2013-03-28 20:22 青岛欧姆网络科技 阅读(350) 评论(0) 推荐(0)
摘要: System.InvalidOperationException: This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.由错误信息可知MVC2出于对网站数据的保护,默认禁止通过get的请求返回JsonResult数据,你可以在返回Json时,传入第二个参 阅读全文
posted @ 2013-03-26 16:05 青岛欧姆网络科技 阅读(3134) 评论(0) 推荐(1)
摘要: Area 是Route中类似命名空间的概念,可以将多个有controller、view、route组成的集合分开,在相对大的项目中比较有用。1.创建Area新建一个MVC项目,在解决方案上面右键“添加Area”。添加后,你会发现解决方案里面多了一个顶级目录Area,下面是一个小的MVC项目。2.注册Area在Application_Start()方法里,AreaRegistration.RegisterAllAreas();3.在地址栏中输入Area/Controller/Action即可访问Area中的Controller等内容。4.默认情况下,你需要在路由注册里面加入命名空间以防止出现相同 阅读全文
posted @ 2013-03-26 10:28 青岛欧姆网络科技 阅读(220) 评论(0) 推荐(0)
摘要: 一、 自定义路由需要继承RouteBase类RouteBase类有两个抽象方法:1.GetRouteData和GetVirtualPathGetRouteData用于重构RouteData数据,GetVirtualPath用于重写产生的URL。下面通过一个例子来说明如何自定义自己的路由:1. 新建一个ControllerView Code 1 namespace URLsAndRoutes.Controllers {2 public class LegacyController : Controller {3 public ActionResult GetLegacyURL(string le 阅读全文
posted @ 2013-03-26 09:44 青岛欧姆网络科技 阅读(383) 评论(0) 推荐(0)
摘要: 1.Html.ActionLink();@Html.ActionLink("About this application", "About") //产生连接到同一controller的Action方法@Html.ActionLink("About this application", "About", "MyController") //产生连接到另一个controller的方法。//带入其他参数@Html.ActionLink("About this application" 阅读全文
posted @ 2013-03-24 12:12 青岛欧姆网络科技 阅读(168) 评论(0) 推荐(0)
摘要: 1. 指定Controller、ActionRoutes.MapRoute("","{controller}/{action}");匹配:http://www.xxx.com/home/Index.2.带默认参数指定Routes.MapRoute("","{controller}/{action}",new {controller="Home",action="Index"});匹配:http://www.xxx.com/home/Index.http://www.xxx.c 阅读全文
posted @ 2013-03-24 10:46 青岛欧姆网络科技 阅读(564) 评论(0) 推荐(1)
摘要: 采用CodeFirst模式开发过程中避免不了实体类跟数据库字段不匹配的问题。例如:在程序中定义了Product类 public class Product { [HiddenInput(DisplayValue=false)] public int ProductID { get; set; } [Required(ErrorMessage="Please enter a product name")] public string Name { get; set; } [Required(ErrorMessage="P... 阅读全文
posted @ 2013-03-22 20:37 青岛欧姆网络科技 阅读(1528) 评论(0) 推荐(0)
上一页 1 ··· 30 31 32 33 34 35 36 37 38 ··· 46 下一页