asp.net-core-mvc

SQLite in ASP.NET Core with EntityFrameworkCore

谁都会走 提交于 2021-01-20 14:11:45
问题 How do you add and use an SQLite database in an ASP.NET Core web application, using EntityFramework 7 ? I dived into ASP.NET Core the moment I heard about it and created my first web application, I suddenly had a bunch of data that I wanted to store and SQLite seemed like the obvious choice. Since I wanted it to stay with my application, keep it lightweight, simple and avoid setting up a separate database. So how would one go about creating an SQLite database in ASP.NET Core? ASP.NET Core -

Include several references on the second level

雨燕双飞 提交于 2021-01-16 04:54:32
问题 Assume we have this model : public class Tiers { public List<Contact> Contacts { get; set; } } and public class Contact { public int Id { get; set; } public Tiers Tiers { get; set; } public Titre Titre { get; set; } public TypeContact TypeContact { get; set; } public Langue Langue { get; set; } public Fonction Fonction { get; set; } public Service Service { get; set; } public StatutMail StatutMail { get; set; } } With EF7 I would like to retrieve all data from the Tiers table, with data from

Include several references on the second level

老子叫甜甜 提交于 2021-01-16 04:53:46
问题 Assume we have this model : public class Tiers { public List<Contact> Contacts { get; set; } } and public class Contact { public int Id { get; set; } public Tiers Tiers { get; set; } public Titre Titre { get; set; } public TypeContact TypeContact { get; set; } public Langue Langue { get; set; } public Fonction Fonction { get; set; } public Service Service { get; set; } public StatutMail StatutMail { get; set; } } With EF7 I would like to retrieve all data from the Tiers table, with data from

JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than

只谈情不闲聊 提交于 2021-01-14 04:14:07
问题 In my web api when i run project for get data from database got this error .net core 3.1 JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. These are my code my Model public class Product { public int Id { get; set; } public string Name { get; set; } public string ProductText { get; set; } public int ProductCategoryId { get; set; } [JsonIgnore] public virtual

How to add html using Razor templates from database to views at runtime

江枫思渺然 提交于 2021-01-07 01:37:08
问题 In ASP.NET Core 5 MVC shopping cart application users can change shipping price calculation, discount options and other such things at runtime. They are editing Razor templates in text editor outside Visual Studio and outside application using non .NET application. Those templates are saved in database. Views contain hook calls: @inherit ViewPageBase<object> <head> @Hook(ElementName.BeforeHeadContent) ... <body> @Hook(ElementName.Body) ... @Hook(ElementName.Footer) ... </body> Hook method is

How to add html using Razor templates from database to views at runtime

*爱你&永不变心* 提交于 2021-01-07 01:36:54
问题 In ASP.NET Core 5 MVC shopping cart application users can change shipping price calculation, discount options and other such things at runtime. They are editing Razor templates in text editor outside Visual Studio and outside application using non .NET application. Those templates are saved in database. Views contain hook calls: @inherit ViewPageBase<object> <head> @Hook(ElementName.BeforeHeadContent) ... <body> @Hook(ElementName.Body) ... @Hook(ElementName.Footer) ... </body> Hook method is

How i can restrict the Authorize attribute to certain users only, inside my asp.net core mvc web application

倖福魔咒の 提交于 2021-01-07 01:22:24
问题 I have created a new asp.net MVC core web application and i set it to use Work or School Accounts with multiple organization, as follow:- now if i add [Authorize] attribute to an action method then the user will be asked to login first. but my question is how i can only allow certain users to access the action method? Second question , is how i can prevent users from logging to the application unless they are inside a predefined list? 回答1: You have to add the Roles in authorize attribute. For

How i can restrict the Authorize attribute to certain users only, inside my asp.net core mvc web application

你说的曾经没有我的故事 提交于 2021-01-07 01:15:19
问题 I have created a new asp.net MVC core web application and i set it to use Work or School Accounts with multiple organization, as follow:- now if i add [Authorize] attribute to an action method then the user will be asked to login first. but my question is how i can only allow certain users to access the action method? Second question , is how i can prevent users from logging to the application unless they are inside a predefined list? 回答1: You have to add the Roles in authorize attribute. For

Conditionally render disabled button in asp.net core view

丶灬走出姿态 提交于 2021-01-05 07:50:07
问题 I have a button in my view which I would like to be disabled based on certain condition. Below is my view: @{ var myCondition = false; myCondition = //set condtion here } <input type="submit" value="Create" class=" btn btn-primary" /> So based on myCondition I want to disabled/enable my button. I can do like: @if(myCondition) { <input type="submit" value="Create" disabled="disabled" class=" btn btn-primary" /> } else { //enable it here } Is there any elegant way to do that in .net core. Can

Why is there no Dispose method to override in .Net Core?

徘徊边缘 提交于 2021-01-05 07:40:20
问题 I am trying to dispose of my DbContext in my GenericRep from my Generic Service. My generic repo is implementing the pattern described here: https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application I have set up the first part in my repo: public class GenericRepository<T> : IGenericRepository<T>, IDisposable where T: BaseEntity { protected readonly