随笔分类 - Mvc
Mvc
摘要:一般的基于浏览器跨域的主要解决方法有这么几种:1.JSONP 2.IFrame方式 3.通过flash实现 4.CORS跨域资源共享 ,这里我们主要关注的是在MVC里面的CORS跨域,其余的方式大家可以在网上找到相关的知识看一下。CORS的原理: CORS定义一种跨域访问的机制,可以让AJAX实...
阅读全文
摘要:在我们做正常的MVC的开发中,一些基本的控件已经够用了,但是有时候我们需要用到库里面没有的一些控件,比如RadioButtonListFor和CheckBoxListFor这类的列表控件,在MVC库里面没提供,需要自己来扩展一下。我们通过MvcHtmlString扩展的控件,最终还是被转换为htm...
阅读全文
摘要:实现代码如下:View Code 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.Mvc; 6 using System.Reflection; 7 using System.Text; 8 9 namespace HtmlHelperDemo.Extension10 {11 public class ExportExcelResult : ActionResult12 {13 pri...
阅读全文
摘要:我们在做上传文件的时候,文件上传的逻辑是一样的,操作数据库的逻辑不一样,那我们怎么将这个功能统一封装起来呢,因为上传文件的文件流为空和不为空的时候,操作是不一样的,我们只能将操作作为参数传进去,也就是下面的action1和action2,看下面的代码首先看一下封装的代码 /// /// 上传文件 /// /// 控件名称 /// 文件夹路径 /// 上传成功后的操作 /// 文件流为空时的操作 /// 文件全路径 public static JsonResult UploadF...
阅读全文
摘要:public JsonResult AddProDoc(ProjectDoc doc) { try {///文件 HttpPostedFileBase file = Request.Files["File"];///图片 //WebImage image = WebImage.GetImageFromRequest(""); if (file != null) { var fil...
阅读全文
摘要:用Mvc3自带的Json()方法返回Json类型的数据有Bug,就是对带外键的表进行数据转换时报错“序列化类型为“System.Data.Entity.DynamicProxies. 。。。”的对象时检测到循环引用”的错误,于是我就自己写了个解决了这个问题,可能会有一些小Bug,请大牛们指出! 1 /// 2 /// 绑定分页数据源格式转换 3 /// 4 /// 实体 5 /// 数据源 6 /// 标记(“0”只显示List:'[{},{}]'"1"显示count,+List:{count:...
阅读全文
摘要:直接上代码吧,代码可以说明一切!using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Text;using System.Reflection;namespace ProjectManageSys.Extension{ public static class ConvertData { /// <summary> /// 数据源转换为Json格式 /// </summary> /// <typeparam name="TE
阅读全文
摘要:在Mvc里面我们知道有自带的Filter方法,也就是我们说的Aop横向切面编程首先自定义CustomeFilterAttribute类,继承FilterAttribute方法,同时继承IExceptionFilter接口(还可以继承IActionFilter, IAuthorizationFilter IResultFilter等接口),然后实现OnException方法先看代码:public class CustomeFilterAttribute : FilterAttribute, IExceptionFilter { public void OnException(Exceptio..
阅读全文
摘要:#region 绑定下拉菜单 /// /// 绑定下拉菜单 /// /// /// /// /// /// /// private void BindDropList(string viewDataName, IEnumerable source, string dataValueField, string dataTextField, string selectval) { ViewData[viewDataName] = new SelectList(source, dataValueField, dataTextField, selectval); }在页面上绑定@H...
阅读全文
摘要:VIEW 代码@using (Html.BeginForm("Upload", "UploadFile", FormMethod.Post, new { enctype = "multipart/form-data" })){}Controller 代码 [HttpPost] public ActionResult Upload(HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { // extract only the
阅读全文

浙公网安备 33010602011771号