MVC Razor引擎的一些技巧

转自:http://www.cnblogs.com/chuifeng/archive/2011/04/11/2012296.html
MVC Razor的使用
1.@转义
写法:@@
实例:shuxin556@@163.com

2.@注释
写法:@**@
3.取request
例如:@Request.Url
4.@@作用域和Html混合使用
作用域使用{}描述,在作用域内可以直接输出html.
例如:@{
//定义变量i
int i = 1;
12

[......]

阅读全文

ASP.NET MVC 3 获取当前Action中返回的View内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class PopularController : Controller
    {
        //
        // GET: /Popular/
 
        public ActionResult Index()
        {
 
                ViewBag.Number = 10;
                var sb = new StringBuilder();
                var writer = new StringWriter(sb);
                var view = new RazorView(this.ControllerContext, Url.Content("~/Views/Popular/boardOffset.cshtml"), null, false, new[] { "cshtml" });
                var content = new ViewContext(this.ControllerContext, view, this.ViewData, this.TempData, writer);
 
                view.Render(content, writer);//此处的Writer里的内容就是渲染好的HTML
            }
            return View();
 
    }

(转)ASP.NET MVC 3 网站优化总结(一) 使用 Gzip 压缩

网站开启 Gzip 压缩的好处相信很多人都已经清楚,这样做可以提高网站的性能。那么为什么很多网站没有开启 Gzip 压缩功能呢?原因有4点:防病毒软件、浏览器 bug、网站代理和服务器未配置。

使用 IE6 时不会发送 Accept-Encoding 请求头,这样就不支持 Gzip 压缩功能了,所以这里号召大家使用 Google Chrome。在 ASP.NET MVC 3 中我们通过实现 ActionFilter 来实现,如下:

public class CompressAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var acceptEncoding = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
        if (!string.IsNullOrEmpty(acceptEncoding))
        {
            acceptEncoding = acceptEncoding.ToLower();
            var response = filterContext.HttpContext.Response;
            if (acceptEncoding.Contains("gzip"))
            {
                response.AppendHeader("Content-encoding", "gzip");
                response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
            }
            else if (acceptEncoding.Contains("deflate"))
            {
                response.AppendHeader("Content-encoding", "deflate");
                response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
            }
        }
    }
}

这样,我们在要实现 Gzip 压缩的 Action 上添加[Compress][......]

阅读全文

MVC 3.0 验证你的Model

转自:http://www.cnblogs.com/lukun/archive/2011/08/01/2124088.html

概述

 

上节我们学习了Model的数据在界面之间的传递,但是很多时候,我们在数据传递的时候为了确保数据的有效性,不得不给Model的相关属性做基本的数据验证。

本节我们就学习如何使用 System.ComponentModel.DataAnnotations 命名空间中的特性指定对数据模型中的各个字段的验证。

这些特性用于定义常见的验证模式,例如范围检查和必填字段。而 DataAnnotations 特性使 MVC 能够提供客[......]

阅读全文

Html.BeginForm添加属性

Html.BeginForm(
action, controller, FormMethod.Post, new { enctype=”multipart/form-data”})

Html.BeginForm(
null, null, FormMethod.Post, new { enctype=”multipart/form-data”})

Html.TextBoxFor 给Input添加属性

给一个TextBox添加多个属性
 
1
@Html.TextBoxFor(m => m.UserName, new Dictionary() { { "placeholder", "输入邮箱" },{"error","输入错误"} });

 

给一个TextBox添加一个属性
1
@Html.TextBoxFor(m => m.UserName, new { placeholder="输入邮箱" }});

转:mongodb 总结

转自:http://www.osseye.com/?p=653

mongodb由C++写就,其名字来自humongous这个单词的中间部分,从名字可见其野心所在就是海量数据的处理。关于它的一个最简洁描述为:scalable, high-performance, open source, schema-free, document-oriented database。MongoDB的主要目标是在键/值存储方式(提供了高性能和高度伸缩性)以及传统的RDBMS系统(丰富的功能)架起一座桥梁,集两者的优势于一身。

安装及使用:

首先在Ubuntu上安装MongoDB。

下载Mo[......]

阅读全文

编译Django文档报错解决方案

Ticket #17177 (closed Bug: duplicate)

 

Opened 3 weeks ago

 

Last modified 3 weeks ago

Building django documentation with Sphinx 1.1

Reported by:
gavenkoa
Owned by:
poirier

Component:
Documentation
Version:
1.3

Severity:
Normal
Keywords[......]

阅读全文

Django resources ¶

This page lists open source projects and applications regarding Django, the framework for perfectionists with deadlines.

Feel free to update this page to improve the content as you see an opportunity to add or modify a resource, or to remove any unmaintained project from the list.

 

    [......]

阅读全文

Stack Overflow clones – Meta Stack Overflow

Most active that look like the best bets (as of June 2011)

阅读全文