- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
锐拓云-Razor的基础语法介绍
教程目录帖:http://www.sufeinet.com/thread-39989-1-1.html
Razor介绍
Razor是包含了模板引擎和动态编译两部分。本部分就简单记录了模板引擎的一些语法,之后用Razor做一个代码生成器,就使用Razor的语法来。
Razor的发布是和MVC一起的,作为MVC的视图模板引擎。
Razor文件类型
Razor可以在vb.net和C#中使用。分别对应了两种文件类型,.vbhtml和.cshtml
Razor标识符
@字符被定义为Razor服务器代码块的标识符。和在aspx页面中使用<%%>中写服务器代码一个道理。在vs工具里面提供了代码着色和智能感应的功能。如下面代码 [HTML] 纯文本查看 复制代码 [/align][align=left]@{string name= "苏飞";}
<span>@name</span>
<span>@DateTime.Now.ToString("yyyy-MM-hh")</span>[/align][align=left]
Razor的作用域
在上面一个例子中都已经使用到了大括号{},不错,大括号里面的就是表示作用域的范围,用形如@{code}来写一段代码块。
[HTML] 纯文本查看 复制代码 @{
string name= "苏飞";
@name
} 在作用域(代码块)中输出也是用@符号的。
@@helper的语法
[HTML] 纯文本查看 复制代码 @helper sum(int a,int b)
{
var result=a+b;
@result
}
<div >
<p>@@helper的语法</p> <p>2+3=@sum(2,3)</p>
<p>5+9=@sum(5,9)</p>
</div>
Html.Raw()输出HTML代码
[HTML] 纯文本查看 复制代码 @Href("~/")//表示网站的根目录
@Html.Raw(Module.Content) 输出HTML,如:@Html.Raw('<font color='red'>红字</font>'),就会显示出红色的”红字“,[/align][align=left] 不用的话会直接显示这段html字符串(<font color='red'>红色文字</font>)[/align][align=left]
和文字字母紧邻着的写法
[HTML] 纯文本查看 复制代码 <div name="su@name">我的名字是@name</div> 如果安上面的写法那么一定会报错 正确的写法应该是 [HTML] 纯文本查看 复制代码 <div name="su@(name)">我的名字是@(name)</div>
用Razor和html代码混合编写
在Razor中写html代码和html代码中写Razor语句都是可以的,并且还有智能提示。 [C#] 纯文本查看 复制代码 a.在作用域内如果是以html标签开始则视为文本输出
b.如果要输出@,则使用@@
c.如果要输出非html标签和非Razor语句的代码,则用@:,他的作用是相当于在处于html下面编写一样了[/align][align=left] ,如在@:后面可以加上@就是表示Razor语句的变量 [HTML] 纯文本查看 复制代码 @{
Layout = null;
}
<html lang="en">
<head runat="server">
<meta charset="UTF-8">
<meta name="keywords" content="@Model.siteinfo.keywords">
<meta name="description" content="@Model.siteinfo.description">
<title>@(Model.siteinfo.title +"-" + Model.siteinfo.sitename)</title>
<link href="//cdn.ruituoyun.com/css/bootstarp/bootstrap-combined-2.3.1.min.css" rel="stylesheet" />
<link href="//cdn.ruituoyun.com/css/swiper/swiper-4.0.7.min.css" rel="stylesheet" />
<link href="//static.ruituoyun.com/css/layout/css/layoutit1.css" rel="stylesheet" />
<link href="//static.ruituoyun.com/css/iconfont.css" rel="stylesheet" />
<script src="//cdn.ruituoyun.com/js/jquery/jquery-2.0.0.min.js" type="text/javascript"></script>
<script src="//cdn.ruituoyun.com/js/bootstrap/bootstrap-3.3.0.min.js" type="text/javascript"></script>
<script src="//cdn.ruituoyun.com/js/swiper/swiper-4.0.7.min.js"></script>
<script src="//cdn.ruituoyun.com/js/layer/layer.js" type="text/javascript"></script>
<script src="//static.ruituoyun.com/js/layout/js/index.js" type="text/javascript"></script>
<script src="//static.ruituoyun.com/js/layout/js/message.js" type="text/javascript"></script>
<script src="//static.ruituoyun.com/js/drag/helper.js" type="text/javascript"></script>
</head>
<body class="edit">
<div class="container-fluid">
<!--导航-->
<header class="header6 allever" id="mould18456" data-pid="18456" data-type="1">
<div class="logo">
<a href="/">
<img src="//upload.ruituoyun.com/Upload/website/64/image/2019/08/24/6370225998419340338337377.png" alt="锦鸡坊餐饮">
</a>
</div>
<div class="nav">
<ul>
@foreach (var info in Model.GetList("栏目", 10, "parentid=0"))
{
<li>
<a href="@info.link">
<h5>
@info.name
</h5>
<h6>
@info.ename
</h6>
</a>
</li>
}
</ul>
</div>
</header>
<!--轮播-->
<div class="banner1 allever" id="mould18496" data-pid="18496" data-type="2">
<div class="swiper-container swiper1 swiper-container-horizontal" data-swiper="{autoplay:{delay: 3000,disableOnInteraction: false},slidesPerView:1,spaceBetween:0,loop:true,}">
<div class="swiper-wrapper">
@foreach (var info in Model.GetList("轮播图", 10, "type='pc'"))
{
<div class="swiper-slide">
<a>
<img src="@info.url" alt="@info.title">
</a>
</div>
}
</div>
<div class="swiper-button-next">
</div>
<div class="swiper-button-prev">
</div>
</div>
</div>
<!--简介-->
<div class="row-fluid allever" id="mould18758" data-pid="18758" data-type="98">
<div class="span12">
<div class="row-fluid allever" id="mould18783" data-pid="18783" data-type="98">
<div class="span" style="width:570px">
<div class="fixed_img allever" id="mould18785" data-pid="18785" data-type="14">
<a>
<img src="//upload.ruituoyun.com/Upload/website/64/image/2019/08/26/6370243193957692766635344.png" alt="">
</a>
</div>
</div>
<div class="span" style="width:630px">
<div class="row-fluid allever" id="mould18784" data-pid="18784" data-type="98">
<div class="span12">
<div class="rtyTextEdit allever" id="mould18786" data-pid="18786" data-type="16">
<p>
品牌起源
</p>
</div>
<div class="rtyTextEdit allever" id="mould18787" data-pid="18787" data-type="16">
<p>
Brand Origin
</p>
</div>
<div class="rtyTextEdit allever" id="mould18788" data-pid="18788" data-type="16">
@{ var obj = Model.GetOneObj("基本页", "lanmuid=3574"); }
<p>
@Model.GetTopStr(Model.StripHTML(obj.context), 240)...
</p>
</div>
<div class="fiexd_btn allever" id="mould18791" data-pid="18791" data-type="15">
<a href="/about/3574" class="btn1">
M O R E
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--特色美食-->
<div class="row-fluid allever" id="mould18792" data-pid="18792" data-type="98">
<div class="span12">
<div class="rtyTextEdit allever" id="mould18795" data-pid="18795" data-type="16">
<p>
特色美食
</p>
</div>
<div class="rtyTextEdit allever" id="mould18798" data-pid="18798" data-type="16">
<p>
Featured Delicacies
</p>
</div>
<div class="img_all allever" id="mould18793" data-pid="18793" data-type="5">
<div class="center_img">
<ul>
@foreach (var info in Model.GetList("产品", 5, "hot=1"))
{
<li>
<a href="/productinfo/@info.lanmuid/@info.productid/2">
<img src="@info.url" alt="@info.title">
<div>
@Model.GetTopStr(info.title, 15)
</div>
</a>
</li>
}
</ul>
</div>
</div>
</div>
</div>
<!--店面-->
<div class="row-fluid allever" id="mould18799" data-pid="18799" data-type="98">
<div class="span12">
<div class="rtyTextEdit allever" id="mould18800" data-pid="18800" data-type="16">
<p>
店面展示
</p>
</div>
<div class="rtyTextEdit allever" id="mould18801" data-pid="18801" data-type="16">
<p>
Shop Show
</p>
</div>
<div class="row-fluid allever" id="mould18814" data-pid="18814" data-type="98">
<div class="span12">
<div class="banner1 allever" data-ltype="1" id="mould18812" data-pid="18812" data-type="2">
<div class="swiper-container swiper2 swiper-container-horizontal" data-swiper="{autoplay:{delay: 3000,disableOnInteraction: false},slidesPerView:2,spaceBetween:50,loop:true,}">
<div class="swiper-wrapper">
@foreach (var info in Model.GetList("新闻", 9999, "lanmuid=2915 and hot =1 or lanmuid=2916 and hot =1"))
{
<div class="swiper-slide">
<a>
<img src="@info.url" alt="@info.title">
</a>
</div>
}
</div>
</div>
<div class="swiper-button-next">
</div>
<div class="swiper-button-prev">
</div>
</div>
</div>
</div>
<div class="fiexd_btn allever" id="mould18813" data-pid="18813" data-type="15">
<a href="/honor/3584" class="btn1">
M O R E
</a>
</div>
</div>
</div>
<!--优势加盟-->
<div class="row-fluid allever" id="mould18831" data-pid="18831" data-type="98">
<div class="span12">
<div class="rtyTextEdit allever" id="mould18833" data-pid="18833" data-type="16">
<p>
加盟优势
</p>
</div>
<div class="rtyTextEdit allever" id="mould18840" data-pid="18840" data-type="16">
<p>
Joining Advantage
</p>
</div>
<div class="ys15 allever" id="mould18832" data-pid="18832" data-type="29">
<ul class="clearfix">
<li>
<a href="/about/3578" class="ys15-box">
<p class="num">
NO.01
</p>
<h3 class="title">
技术支持
</h3><span class="line"></span>
<p class="des">
加盟后可提供在线技术服务,保障问题高效。快速的解决, 让服务商、客户没有后顾之忧。
</p>
</a>
</li>
<li>
<a href="/about/3578" class="ys15-box">
<p class="num">
NO.02
</p>
<h3 class="title">
客服支持
</h3><span class="line"></span>
<p class="des">
专属QQ群一对一对接答疑;7x12小时400客服热线;客服专员:解决生产、技术和产品功能等问题;
</p>
</a>
</li>
<li>
<a href="/about/3578" class="ys15-box">
<p class="num">
NO.03
</p>
<h3 class="title">
培训支持
</h3><span class="line"></span>
<p class="des">
定期针对服务商务人员的需求开展线相关培训,进行产品、销售、售后、管理等相关培训
</p>
</a>
</li>
<li>
<a href="/about/3578" class="ys15-box">
<p class="num">
NO.04
</p>
<h3 class="title">
最大折扣
</h3><span class="line"></span>
<p class="des">
提供最大折扣优惠辅助商务更好的发展公司,储备人才,拓展市场。
</p>
</a>
</li>
<li>
<a href="/about/3578" class="ys15-box">
<p class="num">
NO.05
</p>
<h3 class="title">
运营支持
</h3><span class="line"></span>
<p class="des">
每月策划客户政策和销售活动,利用多元化的手段协助合作商开拓市场,降低销售难度;定期组织老板和管理层交流公司经营、团队打造;
</p>
</a>
</li>
<li>
<a href="/about/3578" class="ys15-box">
<p class="num">
NO.06
</p>
<h3 class="title">
物料支持
</h3><span class="line"></span>
<p class="des">
定期给服务商务人员提供各种产品教程、销售资料,极大限度协助服务商务人员完成业绩提升
</p>
</a>
</li>
</ul>
</div>
</div>
</div>
<!--底部-->
<div class="row-fluid allever" id="mould18855" data-pid="18855" data-type="98">
<div class="span6">
<div class="row-fluid allever" id="mould18856" data-pid="18856" data-type="98">
<div class="span12">
<div class="row-fluid allever" id="mould18858" data-pid="18858" data-type="98">
<div class="span12">
<div class="rtyTextEdit allever" id="mould18859" data-pid="18859" data-type="16">
<p>
@Model.siteinfo.title
</p>
</div>
<div class="row-fluid allever" id="mould18860" data-pid="18860" data-type="98">
<div class="span" style="width:365px">
<div class="rtyTextEdit allever" id="mould18861" data-pid="18861" data-type="16">
<p>
联系电话:@Model.siteinfo.mobile<br>联系邮箱:@Model.siteinfo.email<br>品牌官网:@Model.siteinfo.homepage<br>联系地址:@Model.siteinfo.address
</p>
</div>
</div>
<div class="span" style="width:235px">
<div class="fixed_img allever" id="mould18862" data-pid="18862" data-type="14">
<a>
<img src="//upload.ruituoyun.com/Upload/website/64/image/2019/08/27/6370250091917284914018898.png" alt="">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="span6">
<div class="row-fluid allever" id="mould18857" data-pid="18857" data-type="98">
<div class="span12">
<div class="ly5_all allever" id="mould18863" data-pid="18863" data-type="12">
<div class="cen_ly" id="msg">
<p>
MERCHANTS JOINED
</p>
<p>
招商加盟
</p>
<div>
<input type="text" class="name" placeholder="姓名" v-model="model.name" />
</div>
<div>
<input type="text" class="phone" placeholder="手机" v-model="model.mobile" id="mmobile"/>
</div>
<div>
<textarea class="textcont" placeholder="留言" v-model="model.context"></textarea>
</div>
<div>
<input type="button" class="btn-mesSubmit" v-on:click="addmsg()" value="提交">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="footer allever" id="mould18873" data-pid="18873" data-type="9">
<div class="footer-foot">
<p>
@DateTime.Now.ToString("yyyy") @Model.siteinfo.copyright 版权所有 丨 备案号: @Model.siteinfo.icp 丨 技术支持:@Model.siteinfo.jishuzhichi
</p>
</div>
</div>
</div>
<script src="http://cdn.ruituoyun.com/js/vue/vue-2.6.9.min.js"></script>
<script>
var rw = new Vue({
el: "#msg",
data: {
model: {}
},
methods: {
addmsg: function () {
$.post("/addmessage", { model: JSON.stringify(rw.model) }, function (res) {
if (res.msgCode == 0) {
rw.model = {};
layer.msg(res.msg, { time: 800, zIndex: 1000, offset: "300" });
} else if (res.msgCode == 1) {
$("input[name='mname']").focus();
layer.tips(res.msg, '#mname', {
tips: [1, '#3595CC'],
time: 800
});
} else if (res.msgCode == 2) {
$("input[name='mmobile']").focus();
layer.tips(res.msg, '#mmobile', {
tips: [1, '#3595CC'],
time: 800
});
} else if (res.msgCode == 3) {
$("textarea[name='mcontent']").focus();
layer.tips(res.msg, '#mcontent', {
tips: [1, '#3595CC'],
time: 800
});
}
}, "json");
}
}
});
</script>
@Html.Raw(Model.siteinfo.tongjicode)
@Html.Raw(Model.siteinfo.baidukefu)
</body>
</html>
|
|