asp.net-core-mvc

@helper directive no longer works out of the box in ASP.NET5 MVC6 beta4.

拜拜、爱过 提交于 2019-12-08 15:40:05
问题 Since I updated my ASP.NET5 project to beta4 (the one included with Visual Studio 2015 RC), any of my Razor views where I use a helper, such as: @helper foo() { <h2>Bar</h2> } results in the following error: error CS0103: The name 'helper' does not exist in the current context. Is the @helper directive no longer supported? Can someone point me to anything useful about the issue? 回答1: The @helper directive was removed since beta 4 because it imposed too many restrictions on other Razor

Get DbSet from type

北城余情 提交于 2019-12-08 15:07:18
问题 I am attempting to make a generic table viewer/editor for an MVC 6 application. I currently use Context.GetEntityTypes(); To return me a list of tables. Now I need to fetch the data for a specific type. My current implementation is: // On my context public IQueryable<dynamic> GetDbSetByType(string fullname) { Type targetType = Type.GetType(fullname); var model = GetType() .GetRuntimeProperties() .Where(o => o.PropertyType.IsGenericType && o.PropertyType.GetGenericTypeDefinition() == typeof

Implementing social login in asp.net core 2.2 with custom db tables without using identity

断了今生、忘了曾经 提交于 2019-12-08 13:04:22
问题 I am trying to implement social login features in asp.net core 2.2 without using default feature as given here. I couldn't find any where that shows implementation without using default identity. I have already implemented custom login mechanism to handle user authentication, i.e. there is a user table that stores emailid and its password. When user login it will validate from user table entry. In the same way I want to implement social logins like facebook, twitter, linkedin, microsoft,

NullReferenceException thrown while reading config.json in MVC6

亡梦爱人 提交于 2019-12-08 11:33:04
问题 I'm working on MVC6 webapp. My Startup.cs has the following code- public class Startup { public static Microsoft.Framework.ConfigurationModel.IConfiguration Configuration { get; set; } public Startup(IHostingEnvironment env) { //following line throws NullReferenceException Configuration = new Configuration().AddJsonFile("config.json").AddEnvironmentVariables(); } } config.json- { "Data": { "DefaultConnection": { "ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted

outside of scope when use a service in Configure method?

不羁的心 提交于 2019-12-08 11:17:39
问题 Below is pseudo code from my textbook, and I'm confused about use a service in configure method public class ConcreteA { public static Run(IServiceProvider serviceProvider) { ConcreteB _concrete = serviceProvider.GetRequiredService<ConcreteB>(); ... //use ConcreteB instance } } __________________________________________________________ // startup.cs public void ConfigureServices(IServiceCollection services) { services.AddScoped<ConcreteA>; services.AddScoped<ConcreteB>; } public void

Moving Cache Profiles Settings to appsettings.json in ASP.NET Core

霸气de小男生 提交于 2019-12-08 10:22:49
问题 I would like to be able to edit the cache profile settings in my config.json file. You could do something similar in ASP.NET 4.6 with the web.config file. This is what I have now: services.ConfigureMvc( mvcOptions => { mvcOptions.CacheProfiles.Add( "RobotsText", new CacheProfile() { Duration = 86400, Location = ResponseCacheLocation.Any, // VaryByParam = "none" // Does not exist in MVC 6 yet. }); }); I would like to do something like this: services.ConfigureMvc( mvcOptions => { var

ASP.NET Core 2.1 strange submenu appears in Manage page

*爱你&永不变心* 提交于 2019-12-08 10:00:25
问题 This is my Manage page that was generated by the Scaffolded Identity. Previously this weird Manage your account header with the subheading: Change your account settings and menu did not appear. The only thing that showed was the form in the image and the Manage Account header located directly above the form but I'm not sure why suddenly this extra header and menu appears. I've tried searching on the page itself but it doesn't show up in the code. Is this a configuration somewhere? EDIT: Added

Can't Update Partial View With Ajax ASP.NET Core MVC

三世轮回 提交于 2019-12-08 09:31:08
问题 I want to update my partial View with Ajax, but for some reason, it doesn't work. If I use load method (and comment ajax code), it works. this is my code: this is my main View: @model IEnumerable<WebApplicationMVC.Models.Test> @{ ViewData["Title"] = "Testing"; } <div id="partial"> @await Html.PartialAsync("Question", Model.ToList()[0]) </div> <input type="button" id="b" value="next" class="btn btn-default" /> <script> $("#b").click(function () { //this code doesn't work $.ajax({ url: 'Test

Angular2 component without view annotation

半腔热情 提交于 2019-12-08 08:45:32
I would like to be able to use Angular2 to do client-side databinding on my server-rendered pages (ASP.Net MVC6). Is it possible to do this without adding a @view template? Instead of defining it inline or creating an external template, I would like to enclose a block of server-rendered HTML with the app element. This was how I did it in Angular1, as it allows me to choose whether to databind on the server-side or on the client-side. Thanks. You can do something similar, that is probably what you want. Take this example: import {Component, View, bootstrap} from "angular2/angular2"; @Component(

ASP.NET Core Route Change

一笑奈何 提交于 2019-12-08 08:10:33
问题 I need to update a handful of static web pages, and I would like to take this time to recreate them using ASP.NET Core (ASP.NET 5 with MVC 6) in Visual Studio 2015. I want to rebuild it using Microsoft's latest technology to make changes easier in the future. When I start the project on localhost, the default website loads up fine but any of the linked pages break because they route to the /Home controller by default. Also, none of the project's jquery , css or images are found when MVC nests