ارتقاء به ASP.NET Core 1.0 - قسمت 11 - بررسی بهبودهای Razor
نویسنده: وحید نصیری
تاریخ: ۱۳۹۵/۰۴/۲۶ ۱۲:۴۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Razor;
namespace Core1RtmEmptyTest.StartupCustomizations
{
public abstract class MyCustomBaseView<TModel> : RazorPage<TModel>
{
public bool IsAuthenticated()
{
return Context.User.Identity.IsAuthenticated;
}
#pragma warning disable 1998
public override async Task ExecuteAsync()
{
}
#pragma warning restore 1998
}
} @inherits Core1RtmEmptyTest.StartupCustomizations.MyCustomBaseView<TModel>
Is Current User Authenticated? @IsAuthenticated()
@functions
{
public string Test()
{
return message;
}
readonly string message = "test";
} @Test() <br /> @message
@inject Microsoft.AspNetCore.Hosting.IHostingEnvironment Host;
[Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
public Microsoft.AspNetCore.Hosting.IHostingEnvironment Host { get; private set; } <div> Running in @Host.EnvironmentName </div>
@inject IOptions<SmtpConfig> Settings;
Views\UploadFileExtensions\Index.cshtml(25,135): error CS1061: 'UserFileViewModel' does not contain a definition for 'UserFile' and no extension method 'UserFile' accepting a first argument of type 'UserFileViewModel' could be found (are you missing a using directive or an assembly reference?)
using System.Text.Encodings.Web; using System.Text.Unicode; using Microsoft.Extensions.WebEncoders;
services.Configure<WebEncoderOptions> (options => {
options.TextEncoderSettings = new TextEncoderSettings (UnicodeRanges.All);
}); @using Menu.Helper
@model IEnumerable<.Models.Entities.Category>
@ShowTree(Model)
@helper ShowTree(IEnumerable<Menu.Models.Entities.Category> categories)
{
foreach (var item in categories)
{
<lidropdown-submenu" : "")">
@Html.ActionLink(item.Name, actionName: "Category", controllerName: "Product", routeValues: new { Id = item.Id, productName = item.Name.ToSeoUrl() }, htmlAttributes: null)
@if (item.Children.Any())
{
<ul>
@ShowTree(item.Children)
</ul>
}
</li>
}
} @model IEnumerable<TR_Mahmodabad.Context.Entities.Navbar>
@functions
{
public void ShowTree(IEnumerable<Navbar> navbars)
{
foreach (var item in navbars)
{
<lidropdown-submenu" : "")">
@Html.ActionLink(item.Title, actionName: "", controllerName: "Product", routeValues: new {Id = item.Id, title = item.Title},htmlAttributes:null)
@if (item.HasChiled)
{
<ul>
@ShowTree(item.Children) // خطا
</ul>
}
</li>
}
}
} @{
ShowTree(item.Children);
} @{
ShowTree(Model);
}