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

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

学无止境,精益求精

   最近在做自学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. [ZZ] RGBM and RGBE encoding for HDR

    Deferred lighting separate lighting rendering and make lighting a completely image-space technique. ...

  2. jQuery+CSS 简单代码实现遮罩层( 兼容主流浏览器 )

    /* ** jQuery版本:jQuery-1.8.3.min.js ** 浏览器:Chrome( v31.0.1650.63 m ),IE11,Firefox( v32.0.1 ),IETester ...

  3. Windows下的Objective-C集成开发环境(IDE)

    Windows下的Objective-C集成开发环境(IDE) 分类: Objective-C2012-04-20 21:54 26631人阅读 评论(42) 收藏 举报 windowside编译器c ...

  4. RT-Thread信号量实际运用—按键点灯

    上面是魔笛开发板上 LED 和按键的 IO 分布,我们通过信号量的方法来同步按键线程和LED 线程,实现当 enter 键按下后,点亮或关闭 LED 的动作. /******************* ...

  5. Why Stored Procedures?

    http://www.w3resource.com/mysql/mysql-procedure.php Stored procedures are fast. MySQL server takes s ...

  6. routing decisions based on paths, network policies, or rule-sets configured by a network administrator

    https://en.wikipedia.org/wiki/Border_Gateway_Protocol Border Gateway Protocol (BGP) is a standardize ...

  7. mybatis 中#{}与${}的区别 (面试题)

    MyBatis/Ibatis中#和$的区别 1. #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号. 如:order by #user_id#,如果传入的值是111,那么解析成sql时的 ...

  8. sqlserver 计算 百分比

    ,),))+'%' As 百分比 NUMERIC(P,S) P的默认值是:38 S的默认值是:-84~127 numeric(a,b)函数有两个参数,前面一个为总的位数,后面一个参数是小数点后的位数, ...

  9. Tinyxml的简单应用

    参考文章: 1-> http://www.cnblogs.com/phinecos/archive/2008/03/11/1100912.html 2-> http://blog.csdn ...

  10. 使用Dom的Range对象处理chrome和IE文本光标位置

    有这样一段js: var sel = obj.createTextRange(); sel.move('character', num); sel.collapse(); sel.select(); ...