MVC 视图 视图引擎Razor

View

View('具体的地址')
地址跳转


<text>

<text> 标签是一个Razor 特殊处理的元素。Razor将<text> 块的内部内容视为内容块,
不呈现包含那些内容的<text> 标签(这意味着只呈现<text>内容内容,不呈现标签本身)。
这使呈现没有被HTML元素包装的多行内容块变得方便。


可以实现多行输出


两个连续的@@符号会被渲染为一个@符号


@:文本输出,跟使用text标签一样,单行输出


显示渲染输出

<span> ISBN@(isbnNumber)</span>

当要渲染输出的代码@前无空格或标记位时,我们需要使用小括弧进行显式的渲染输出


渲染输出动态方法

对于动态方法返回值之类的输出我们使用小括弧将代码闭合起来即可

@(MyClass.MyMethod<AType>())


与纯文本混合

方法一:
@if(foo)
{
    <text>Plain Text</text>
}

方法二:
@if(foo)
{
    @:Plain Text
}


创建Razor委托

创建Razor 委托来复用一些视图逻辑

@{
    Func<dynamic,object> b=
    @<strong>@item</strong>;
}

@b("Bold this")


asp.net mvc 自定义视图引擎 public ThemeableRazorViewEngine() { AreaViewLocationFormats = new[] { //themes "~/Areas/{2}/Themes/{3}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Themes/{3}/Views/Shared/{0}.cshtml", //default "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", }; AreaMasterLocationFormats = new[] { //themes "~/Areas/{2}/Themes/{3}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Themes/{3}/Views/Shared/{0}.cshtml", //default "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", }; AreaPartialViewLocationFormats = new[] { //themes "~/Areas/{2}/Themes/{3}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Themes/{3}/Views/Shared/{0}.cshtml", //default "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.cshtml" }; ViewLocationFormats = new[] { //themes "~/Themes/{2}/Views/{1}/{0}.cshtml", "~/Themes/{2}/Views/Shared/{0}.cshtml", //default "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", //Admin //"~/Administration/Views/{1}/{0}.cshtml", //"~/Administration/Views/Shared/{0}.cshtml", }; MasterLocationFormats = new[] { //themes "~/Themes/{2}/Views/{1}/{0}.cshtml", "~/Themes/{2}/Views/Shared/{0}.cshtml", //default "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" }; PartialViewLocationFormats = new[] { //themes "~/Themes/{2}/Views/{1}/{0}.cshtml", "~/Themes/{2}/Views/Shared/{0}.cshtml", //default "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", //Admin //"~/Administration/Views/{1}/{0}.cshtml", //"~/Administration/Views/Shared/{0}.cshtml", }; FileExtensions = new[] { "cshtml" }; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xunbaogang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值