最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来。

十年河东十年河西,莫欺少年穷

学无止境,精益求精

   最近在做自学MVC,遇到的问题很多,索性一点点总结下。

新建一个非空的MVC项目,我们在查看_Layout.cshtml时,会发现@RenderSection(),@Styles.Render()等标签,那么这些标签的作用是什么呢?

_Layout.cshtml 代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="">
<meta name="format-detection" content="telephone=no">
<meta id="viewport" name="viewport" content="width=750px,minimum-scale=0.5,maximum-scale=5,user-scalable=no" />
<title>@ViewBag.Title</title>
<!--用于在App_Start/BundleConfig.cs中绑定系统所需的通用CSS-->
@Styles.Render("~/Content/css")
<!--用于子页面中绑定特有CSS-->
<!--在子页面中用法:@section css{<link href="~/Content/login.css" rel="stylesheet" />}-->
@RenderSection("css", required: false)
</head>
<body>
<!--Body标签中所含的HTML脚本,如:<Form></Form>-->
@RenderBody()
<!--用于在App_Start/BundleConfig.cs中绑定系统所需的通用JS、Jquery-->
@Scripts.Render("~/bundles/jquery")
<!--用于子页面中绑定特有JS、JQuery-->
<!--在子页面中用法:@section script{<script href="~/Content/login.js"></script>}-->
@RenderSection("scripts", required: false)
</body>
</html>

子页面中设定特定的CSS或JS

@{
ViewBag.Title = "登录";
}
@section css
{
<link href="~/Content/login.css" rel="stylesheet" />
}

BundleConfig.cs 中代码如下

    public class BundleConfig
{
// 有关 Bundling 的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.11.1.min.js",
"~/Scripts/TouchSlide.1.1.js",
"~/Scripts/jquery.Slide.js",
"~/Scripts/jquery.inputbox.js")); bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/common.css")); }
}

以上便是上述标签的用法,好记性不如烂笔头,索性记录下来

补充(2016-11-13)

C#字符串处理的过程中经常会碰到中英文数字等组合的字符串,其中中文字符每个站位为2,英文 数字等站位为1,在截取的过程中不好处理,下面来介绍一种处理中英文字符混合的方法,如下:

#region 截取字符长度 static string CutString(string str, int len)
/// <summary>
/// 截取字符长度
/// </summary>
/// <param name="str">被截取的字符串</param>
/// <param name="len">所截取的长度</param>
/// <returns>子字符串</returns>
public static string CutString(string str, int len)
{
if (str == null || str.Length == || len <= )
{
return string.Empty;
} int l = str.Length; #region 计算长度
int clen = ;
while (clen < len && clen < l)
{
//每遇到一个中文,则将目标长度减一。
if ((int)str[clen] > ) { len--; }
clen++;
}
#endregion if (clen < l)
{
return str.Substring(, clen) + "...";
}
else
{
return str;
}
} /// <summary>
/// //截取字符串中文 字母
/// </summary>
/// <param name="content">源字符串</param>
/// <param name="length">截取长度!</param>
/// <returns></returns>
public static string SubTrueString(object content, int length)
{
string strContent = NoHTML(content.ToString()); bool isConvert = false;
int splitLength = ;
int currLength = ;
int code = ;
int chfrom = Convert.ToInt32("4e00", ); //范围(0x4e00~0x9fff)转换成int(chfrom~chend)
int chend = Convert.ToInt32("9fff", );
for (int i = ; i < strContent.Length; i++)
{
code = Char.ConvertToUtf32(strContent, i);
if (code >= chfrom && code <= chend)
{
currLength += ; //中文
}
else
{
currLength += ;//非中文
}
splitLength = i + ;
if (currLength >= length)
{
isConvert = true;
break;
}
}
if (isConvert)
{
return strContent.Substring(, splitLength);
}
else
{
return strContent;
}
} public static int GetStringLenth(object content)//获取混合字符串长度,根据长度进行长度/前2...后2等方式截取
{
string strContent = NoHTML(content.ToString());
int currLength = ;
int code = ;
int chfrom = Convert.ToInt32("4e00", ); //范围(0x4e00~0x9fff)转换成int(chfrom~chend)
int chend = Convert.ToInt32("9fff", );
for (int i = ; i < strContent.Length; i++)
{
code = Char.ConvertToUtf32(strContent, i);
if (code >= chfrom && code <= chend)
{
currLength += ; //中文
}
else
{
currLength += ;//非中文
} }
return currLength;
}
#endregion

@陈卧龙的博客

MVC字符串处理及MVC @RenderSection小计的更多相关文章

  1. ajax post提交空字符串(string.Empty) MVC接收为null的问题

    ajax post提交空字符串(string.Empty) MVC接收为null的问题 这个问题查了好多资料才知道原因: if (bindingContext.ModelMetadata.Conver ...

  2. 前台JSON字符串,spring mvc controller也接收字符串

    前台JSON字符串,spring mvc controller也接收字符串 前台: $.post(url, { data : JSON.stringify(obj) }, function(data) ...

  3. Pro ASP.NET MVC –第三章 MVC模式

    在第七章,我们将创建一个更复杂的ASP.NET MVC示例,但在那之前,我们会深入ASP.NET MVC框架的细节:我们希望你能熟悉MVC设计模式,并且考虑为什么这样设计.在本章,我们将讨论下列内容 ...

  4. 返璞归真 asp.net mvc (9) - asp.net mvc 3.0 新特性之 View(Razor)

    原文:返璞归真 asp.net mvc (9) - asp.net mvc 3.0 新特性之 View(Razor) [索引页][源码下载] 返璞归真 asp.net mvc (9) - asp.ne ...

  5. 七天学会ASP.NET MVC (三)——ASP.Net MVC 数据处理

    第三天我们将学习Asp.Net中数据处理功能,了解数据访问层,EF,以及EF中常用的代码实现方式,创建数据访问层和数据入口,处理Post数据,以及数据验证等功能. 系列文章 七天学会ASP.NET M ...

  6. 七天学会ASP.NET MVC (二)——ASP.NET MVC 数据传递

    通过第一天的学习之后,我们相信您已经对MVC有一些基本了解. 本节所讲的内容是在上节的基础之上,因此需要确保您是否掌握了上一节的内容.本章的目标是在今天学习结束时利用最佳实践解决方案创建一个小型的MV ...

  7. ASP.NET MVC 5– 使用Wijmo MVC 5模板1分钟创建应用

    开始使用 使用ComponentOne Studio for ASP.NET Wijmo制作MVC5应用程序,首先要做的是安装Studio for ASP.NET Wijmo . 测试环境 VS201 ...

  8. 【MVC 4】4.MVC 基本工具(Visual Studio 的单元测试、使用Moq)

     作者:[美]Adam Freeman      来源:<精通ASP.NET MVC 4> 3.Visual Studio 的单元测试 有很多.NET单元测试包,其中很多是开源和免费的.本 ...

  9. 【MVC 4】3.MVC 基本工具(创建示例项目、使用 Ninject)

    作者:[美]Adam Freeman      来源:<精通ASP.NET MVC 4> 本次将考察三类工具,它们是每一位 MVC 程序员工具库的成员:DI容器.单元测试框架和模仿工具. ...

随机推荐

  1. centos 使用pip安装mysql-python

    直接使用# pip install mysql-python 命令报 EnvironmentError: mysql_config not found 错误 安装mysql-phthon 需要用的my ...

  2. skype msnLite 静态路由

    连接vpn后防止skype和msn重复登陆 route -p add ip网段 mask 子网掩码 本地网管 skyperoute -p add 91.0.0.0 mask 255.0.0.0 192 ...

  3. 【翻译】CEDEC2012 SQUARE ENIX GPGPU实现高速GI烘培工具的方法

     虽然实时GI技术已经趋于成熟了,但出于对不同平台的性能和质量的考虑, 更倾向搭配一些预计算的渲染技术来实现,如给静态物体提供GI的LightMap, 给动态物体提供GI的Irradiance Vol ...

  4. mysql通过data目录恢复数据库

    mysql通过data目录恢复数据库 阅读:次   时间:2010-03-24 06:53:30   字体:[大 中 小]     重装系统后,MySQL服务没有了,但是数据库的文件还在,这个时候我想 ...

  5. Translation Lookaside Buffer

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION In principle, then, e ...

  6. 【php学习】时间函数

    手工画了一张图,来大体概括php中对于时间的处理函数 首先时间戳是这样“1441202665”的一串数字,虽然人看起来麻烦,但是计算机却很容易识别这样的时间表示形式. 所以给计算机看的时间是时间戳,给 ...

  7. php浮点数计算问题

    如果用php的+-*/计算浮点数的时候,可能会遇到一些计算结果错误的问题,比如echo intval( 0.58*100 );会打印57,而不是58,这个其实是计算机底层二进制无法精确表示浮点数的一个 ...

  8. 深入了解php opcode缓存原理

    什么是opcode opcode(operate code)是计算机指令中的一部分,用于指定要执行的操作,指令的格式和规范由处理器的指定规范指定 opcode是一种php脚本编译后的中间语言,就像ja ...

  9. SQL代码创建表例子

    create table class ( code ) primary Key, name ) ); create table student ( code ) primary Key, name ) ...

  10. Solaris 10下Qt编译Oracle 10g驱动

    上回书讲到<Oracle 10g在Solaris 10中安装详解>,现在开始用Qt来编译下Oracle 10g驱动吧!这样就可以通过Qt程序联入Oracle数据库了! Oracle的环境变 ...