asp.net-core-mvc

What to use instead of WebViewPage.RenderPage method in ASP.NET 5 MVC6

末鹿安然 提交于 2019-12-05 08:19:33
Given an example based on old MVC5: Views/Shared/Index.cshtml - a view for a SPA app. It contains some markup and a reference to a layout-page: @{ Layout = "~/Views/Shared/_Layout.cshtml"; } In _Layout.cshtml there're number of includes which are being used via RenderPage helper: @RenderPage("~/Views/Shared/_ImportCssInline.cshtml") @RenderPage("~/Views/Shared/_ImportCssLinks.cshtml") Now in AspNet5 @RenderPage helper isn't available. It was the method of WebViewPage / WebPageBase / WebPageRenderingBase . Now they were replaced by RazorPage . But there's no RenderPage method in it. What should

Cookies in ASP vnext

你说的曾经没有我的故事 提交于 2019-12-05 07:49:45
How can i use cookies in ASP MVC 6? I want to set and read cookie variables . HttpCookie class can't be resolved . Only the following line works but i couldn't find a way to read the cookie after adding it . Response.Cookies.Append("test", "test"); Take a look at how cookies are used in the official MusicStore sample: https://github.com/aspnet/MusicStore/blob/a7ba4f8ffe5ed23b2a2d55e8e1226e64066a7ada/src/MusicStore/Models/ShoppingCart.cs#L152 public string GetCartId(HttpContext context) { var sessionCookie = context.Request.Cookies.Get("Session"); The answer from Victor Hurdugaci applies to pre

Use appsettings to drive environment specific settings such as UseUrls

99封情书 提交于 2019-12-05 07:46:06
When I'm developing locally using VS Code, I'm going to use port 3000 because I'm a hipster. The non-hipsters want it on port 8080 on the server. That's cool, we got this. Microsoft docs give me the following example: public static void Main(string[] args) { var config = new ConfigurationBuilder() .AddJsonFile("hosting.json", optional: true) .AddCommandLine(args) .Build(); var host = new WebHostBuilder() .UseConfiguration(config) .UseKestrel() .Configure(app => { app.Run(async (context) => await context.Response.WriteAsync("Hi!")); }) .Build(); host.Run(); } I don't want to use hosting.json .

ASP.NET Core MVC App Settings

你说的曾经没有我的故事 提交于 2019-12-05 07:40:26
I'm trying to use configuration variables on my ASP.NET Core MVC project. This is where I've got so far: Created an appsettings.json Created an AppSettings class Now I'm trying to inject it on the ConfigureServices, but my Configuration class is either not recognized or when using the full reference: "Microsoft.Extensions.Configuration" the GetSection Method is not recognized, i.e. Configuration class not being recognized GetSection method not being recognized Any ideas on how to use this? The whole configuration approach in .NET Core is really flexible, but not at all obvious at the beginning

ASP.NET mvc View with IEnumerable model and input tag helper

送分小仙女□ 提交于 2019-12-05 07:22:25
In this official ASP.NET Core tutorial , I can use an Input Tag Helper as shown below. But due to a known model binding issue of form elements in a foreach loop , I want to use for loop instead. Question : If I were to replace @foreach (var item in Model) with @for (int i=0; i < Model.Count(); i++) in the following View . What would be my asp-for in <input asp-for="???" /> ? For some reason, intellisense is not recognizing, e.g, Model[i].BlogId or @Model[i].BlogId @model IEnumerable<EFGetStarted.AspNetCore.NewDb.Models.Blog> @{ ViewBag.Title = "Blogs"; } <h2>Blogs</h2> <p> <a asp-controller=

How do I debug an ASPNET Core MVC Application Deployed in Azure

删除回忆录丶 提交于 2019-12-05 07:12:40
I've created a simple ASPNET Core 1.0 MVC app, which I am trying to deploy to Azure using Visual Studio. I am able to run this app locally on my machine using IIS Express, and navigate to my default route and display the page. However, in Azure I always get a 500 error every time, and at this point I am at a loss for how to get additional information. I've enabled detailed request logging in my Azure app, but it doesn't really seem to tell me much. ModuleName="AspNetCoreModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0",

How to define function that returns html in asp.net core

人走茶凉 提交于 2019-12-05 07:11:38
Basically I need something like old asp.net @helper MakeNote(string content) { <p><strong>Note</strong>   @content </p> } or JSX MakeNote(note) { return (<div>Note {note}</div>); } A partial view is not an option. I am happy with either a function returning an IHtmlString, or a function writing to the underlying writer. It also needs to support Razor Syntax (not just string concatenation) inside the function. You might be looking for @functions that use Html.Raw . Here is an example that shows two function styles. The first uses a traditional block body, the second uses an expression-body.

Glimpse diagnostics platform which is full compatible to ASP.NET Core

淺唱寂寞╮ 提交于 2019-12-05 06:58:08
I used Glimpse on the old ASP.NET MVC5 stack and liked it very much cause it gives a pretty and detailed representation of nearly all important data for debugging purpose. Sadly, its not compatible with ASP.NET Core (yet). I tried to install the demo , which assurance to work with ASP.NET Core. But thats not entirely true cause it works on ASP.NET Core, but depends on the old 4.x framework. So it destroys the cross-platform compability, which is not suiteable for me. The app is designed to run on a Linux based server using docker. Although, I would like to benefit from those nice features in

ViewComponents are not async

走远了吗. 提交于 2019-12-05 06:40:54
问题 I am trying to use the ViewComponents.InvokeAsync() feature, but somehow this is not async at all. It is waiting for the component code to render. http://docs.asp.net/en/latest/mvc/views/view-components.html My code is very much similar to the one explained in above example. I am using the layout page which comes when you create new application in MVC 6. I thought that ViewComponent.InvokeAsync() method will render asynchronously with respect to the main page. But it does not. In order to

Populating Dropdown in ASP.net Core

你说的曾经没有我的故事 提交于 2019-12-05 06:30:42
Does anyone know how to deal with Dropdowns in Asp.net core. I think I made myself very complicated to understand the new Asp.net core concept. (I am new to Asp.net Core). I have models called Driver , Vehicle . Basically one can create bunch of vehicles in the master then attach it to the Driver. So that the driver will be associated with a vehicle. My problem is that I am also using viewmodel in some area to combine two different models.(understood little from default template) My problem is I have no idea what is the next step since ASP.net Core is very latest, there are not a lot of