asp.net-core-mvc

Model Required value for only given scenario when form is submitted

时光毁灭记忆、已成空白 提交于 2021-01-28 19:29:59
问题 I have a registration page that asks for your given Country and State. This is all fine and dandy when you are from a Country that has states like in the U.S, but when you are from a country that doesn't have states I would like to leave the state field blank and still allow you to register and submit the page still. In my DB table for Country I have a column set boolean true if they have states and false if they don't. This way when someone selects a country with states it loads the states

Authentication thought Azure AD in application hosted on IIS

自古美人都是妖i 提交于 2021-01-28 12:22:14
问题 Is there possibility to authenticate users through Azure Active Directory when my application written in ASP.NET 5 and MVC 6 is hosted on IIS (not on Azure)? Use case is to have users stored in Azure AD and while login to my application I would checks users in Azure AD. I was thinking about custom ApplicationUserStore which would connect Azure AD. 回答1: Yes, it is definitely possible to authenticate users through Azure Active Directory (AAD) for ASP.NET 5 and MVC 6 application. You could use

Caching objects on httpcontext asp.net core

我是研究僧i 提交于 2021-01-28 10:08:32
问题 I'm trying to migrate from .net framework MVC 5 to .net core 2.0 MVC good old times I can get or set the cached objects by calling HttpContext.Current.Application.Lock(); HttpContext.Current.Application["foo"] = bar; HttpContext.Current.Application.Lock(); but I cant migrated this part of my application to the .net core. How can I handle this on core 2.0? 回答1: HttpContext.Current.Application was a feature that was left in to make applications easier to port over from ASP classic. It has been

ASP .NET Core Identity SignInManager

旧城冷巷雨未停 提交于 2021-01-28 08:52:12
问题 Good day. ASP.NET-Core project was with out authentication. So, I tried to add built-in Identity for this purpose. Tables in database successfully created, new user registered. In Account controller in Login Method SignInManager return success in process. In partial view, where links for Login\Register added injection and library (all looks as default project with authentication, based on its implementation): @using Microsoft.AspNetCore.Identity @inject SignInManager<ApplicationUser>

How to avoid the circular referencing asp.net core mvc [HttpPost(“add-recipe”)] web api

怎甘沉沦 提交于 2021-01-28 08:26:57
问题 My project is Application with Recipes (cooking) .NET Core 5.0 And i have problem with adding a new recipe (HttpPost) web api On postman my response is: "A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles." When i'm creating a new recipe it should use recipeToCreateDto instead of Recipe - which contains all properties

Reference to Type 'Route' claims it is defined in 'System.web'

风格不统一 提交于 2021-01-28 08:18:36
问题 I am trying to add a area to my application but it throws the below error at context.MapRoute I have system.web and system.web.mvc dlls referred in my application. What may be the issue? My application is targeting .Net core 2.0 Any pointers please? 回答1: If you're targeting your projecto to .Net core 2.0 and it's a ASP.NET Core, than you should follow these instructions on microsoft docs. You don't need those references to System.Web. You can do area registration with MapRoute in your startup

How to use PaginatedList with ViewModel using MVC

ε祈祈猫儿з 提交于 2021-01-28 08:01:41
问题 I am trying to find a solution for creating a PaginatedList with a ViewModel. Tutorial (using only an ordinary model) https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/sort-filter-page?view=aspnetcore-2.1 Similar problem How do I paginate through a ViewModel in MVC CORE? MVC/Entity framework core using ViewModel with paging My Code Controller public async Task<IActionResult> Index(string sortOrder, string currentFilter, string searchString, int? page) { ViewBag.NameSortParm = String

How to remove xml root namesapce when using asp.net core

一笑奈何 提交于 2021-01-28 07:35:58
问题 How can i remove the root xml namespace given that I am using asp.net core and the XmlDataContractSerializerOutputFormatter to format the response. All of the returned xml docs have the following format <?xml version="1.0" encoding="utf-8"?> <response xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> some other stuff </response> I need to remove the xmlns:i="http://www.w3.org/2001/XMLSchema-instance" part. 回答1: Please try following code: xmlDoc.Load(@"FILE_PATH"); XmlNodeList header_el =

Passing button value from view to controller aspnet 5

孤人 提交于 2021-01-28 07:33:09
问题 I'm building a aspnet mvc6 application where I want to pass values from View to controller. My view has multiple buttons having IDs and I want to pass the ID of the button which is clicked to my controller using my viewmodel. Controller: public class HomeController : Controller { private SampleDbContext _context; private HomeViewModel _viewmodel; public HomeController(SampleDbContext context, HomeViewModel model) { _viewmodel = model; _context = context; } public IActionResult Index() {

Dapper strongly typed Query returning default object values

橙三吉。 提交于 2021-01-28 04:41:02
问题 just started to use Dapper and like it. I'm having a problem with it, it returns the right number of objects, butthey all have default values for their properties using (var dbConnection = Connection) { await dbConnection.OpenAsync(); const string sQuery2 = @"SELECT * FROM ChipTime WHERE MacAddress = @MacAddress AND ClientId = @ClientId ORDER BY CreateDate Desc"; var chipTimes = dbConnection.Query<ChipTime>(sQuery2, new { ClientId = clientId, MacAddress = id }).ToList(); } chipTimes just has