razor

Setting Layout to null in _Layout.cshtml

前提是你 提交于 2021-02-20 10:19:42
问题 Is there a reason why you would want to set the Layout property to null in a _Layout.cshtml? For example, like this, before rendering the body view? ... <section id="content"> @{ Layout = null; } @RenderBody() </section> ... It seems pretty nonsensical to me, and removing the line setting Layout doesn't change the way page loads work observationally. Is there any reason why you would want to set the Layout property in _Layout.cshtml? 回答1: Layout pages can have a layout too. In nested layouts

如何使用Serilog.AspNetCore记录ASP.NET Core3.0的MVC属性

你说的曾经没有我的故事 提交于 2021-02-19 03:23:27
https://www.cnblogs.com/yilezhu/p/12243984.html 这是Serilog系列的第三篇文章。 第1部分-使用Serilog RequestLogging减少日志详细程度 第2部分-使用Serilog记录所选的终结点属性 第3部分-使用Serilog.AspNetCore记录MVC属性(本文) 第4部分-从Serilog请求记录中排除运行状况检查端点 作者:依乐祝 译文地址: https://www.cnblogs.com/yilezhu/p/12243984.html 原文地址: https://andrewlock.net/using-serilog-aspnetcore-in-asp-net-core-3-logging-mvc-propertis-with-serilog/ 在我 上篇文章 中,我描述了如何配置Serilog的RequestLogging中间件以向Serilog的请求日志摘要中添加其他属性(例如请求主机名或选定的端点名称)。这些属性都在 HttpContext 中可用,因此可以由中间件本身直接添加。 其他属性,例如MVC特定的功能,像操作方法ID,RazorPages处理程序名称或ModelValidationState, 仅 在MVC上下文中可用,因此Serilog的中间件不能直接访问。 在本文中,我将展示如何创建

Passing C# variable using MVC/Razor for use with Dygraph

安稳与你 提交于 2021-02-18 19:47:55
问题 So here is my problem, and I'm sure it's something very simple. I'm relatively new to Web Development and I'm running into a little problem that I just can't figure out. I have this code in an MVC view. . . @{ var data = ""; var count = 1; foreach (var item in ViewModel.Data) { data += count.ToString() + "," + item.Reading.ToString() + "\n"; count++; } } I want to pass this 'data' variable to a very tiny script in order to create a graph using Dygraph. This is what I currently have, and

Passing C# variable using MVC/Razor for use with Dygraph

橙三吉。 提交于 2021-02-18 19:47:24
问题 So here is my problem, and I'm sure it's something very simple. I'm relatively new to Web Development and I'm running into a little problem that I just can't figure out. I have this code in an MVC view. . . @{ var data = ""; var count = 1; foreach (var item in ViewModel.Data) { data += count.ToString() + "," + item.Reading.ToString() + "\n"; count++; } } I want to pass this 'data' variable to a very tiny script in order to create a graph using Dygraph. This is what I currently have, and

MVC CSS on view page (not _layout) not working

北城余情 提交于 2021-02-18 18:54:56
问题 I have a problem with MVC4 CSS. i m including a CSS file named registration.css in an another view page named "registerUser.cshtml". This page is like a content page in mvc4 razor. but problem is that CSS is not working. How can i resolve this. I have also included in BundleConfig.cs as bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/registration.css")); But it is also not working. Help me. 回答1: Use @Styles.Render("~/Content/css") instead of @Styles.Render("~/Content

Is it possible for a lambda function to contain Razor syntax and be executed in a View?

不羁岁月 提交于 2021-02-18 12:32:05
问题 Is it possible to define the contents of a lambda expression (delegate, Action, Func<>) with Razor syntax, so that when this model method is executed in the view, it will insert that Razor content? The intended purpose of this is for our developers to be able to define their own custom content to be inserted at a particular point in the CustomControl's view. The following is stripped-down example code that mimics my current layout. The particular parts of focus are the RenderSideContent

List of All Countries DropDown

大憨熊 提交于 2021-02-18 10:45:34
问题 I used this code to populate my dropdownlist with countries list: public JsonResult GetAllCountries() { var objDict = new Dictionary<string, string>(); foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { var regionInfo = new RegionInfo(cultureInfo.Name); if (!objDict.ContainsKey(regionInfo.EnglishName)) { objDict.Add(cultureInfo.EnglishName, regionInfo.TwoLetterISORegionName.ToLower()); } } var obj = objDict.OrderBy(p => p.Key).ToArray(); return Json(obj

asp.net core系列 49 Identity 授权(上)

喜你入骨 提交于 2021-02-13 18:35:45
原文: asp.net core系列 49 Identity 授权(上) 一.概述 授权是指用户能够访问资源的权限,如页面数据的查看、编辑、新增、删除、导出、下载等权限。ASP.NET Core 授权提供了多种且灵活的方式,包括:Razor pages授权约定、简单授权、Role角色授权、Claim声明授权、Policy策略授权、资源授权、视图授权。    1.1 Razor pages约定授权      Razor pages 约定授权用于 Razor page 应用程序,以及 MVC 中的 Identity Razor Pages 库,不适应于 MVC 中的控制器和视图。如下图适用 MVC 中 Identity Razor Pages 库:          对于Razor pages应用程序,访问权限可以在启动时使用授权约定(Startup.cs),这些约定可为用户授权,并允许匿名用户访问各个页面的文件夹。可以使用cookie 身份验证或ASP.NET Core Identity来进行授权约定。下面是MVC项目添加个人账户后,默认Razor pages约定授权配置如下: services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddRazorPagesOptions

asp.net core系列 49 Identity 授权(上)

半城伤御伤魂 提交于 2021-02-13 11:01:31
一.概述 授权是指用户能够访问资源的权限,如页面数据的查看、编辑、新增、删除、导出、下载等权限。ASP.NET Core 授权提供了多种且灵活的方式,包括:Razor pages授权约定、简单授权、Role角色授权、Claim声明授权、Policy策略授权、资源授权、视图授权。    1.1 Razor pages约定授权      Razor pages 约定授权用于 Razor page 应用程序,以及 MVC 中的 Identity Razor Pages 库,不适应于 MVC 中的控制器和视图。如下图适用 MVC 中 Identity Razor Pages 库:          对于Razor pages应用程序,访问权限可以在启动时使用授权约定(Startup.cs),这些约定可为用户授权,并允许匿名用户访问各个页面的文件夹。可以使用cookie 身份验证或ASP.NET Core Identity来进行授权约定。下面是MVC项目添加个人账户后,默认Razor pages约定授权配置如下: services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddRazorPagesOptions(options => { options.AllowAreas = true ; //

把旧系统迁移到.Net Core 2.0 日记(5) Razor/HtmlHelper/资源文件

。_饼干妹妹 提交于 2021-02-12 00:37:06
net core 的layout.cshtml文件有变化, 区分开发环境和非开发环境. 开发环境用的是非压缩的js和css, 正式环境用压缩的js和css <environment include= " Development " > <link rel= " stylesheet " href= " ~/lib/bootstrap/dist/css/bootstrap.css " /> <link rel= " stylesheet " href= " ~/css/site.css " /> </environment> <environment exclude= " Development " > <link rel= " stylesheet " href= " https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css " asp -fallback-href= " ~/lib/bootstrap/dist/css/bootstrap.min.css " asp -fallback-test- class = " sr-only " asp-fallback-test-property= " position " asp-fallback-test-value= " absolute " />