asp.net-core-mvc

ASP.Net Core localization

坚强是说给别人听的谎言 提交于 2019-12-29 06:49:11
问题 ASP.Net core features new support for localization. In my project I need only one language. For most of the text and annotations I can specify things in my language, but for text coming from ASP.Net Core itself the language is English. Examples: Passwords must have at least one uppercase ('A'-'Z'). Passwords must have at least one digit ('0'-'9'). User name 'x@x.com' is already taken. The E-post field is not a valid e-mail address. The value '' is invalid. I've tried setting the culture

How do I add a parameter to an action filter in asp.net?

折月煮酒 提交于 2019-12-29 05:16:05
问题 I have the following filter attribute, and i can pass an array of strings to the attribute like this [MyAttribute("string1", "string2")] . public class MyAttribute : TypeFilterAttribute { private readonly string[] _ids; public MyAttribute(params string[] ids) : base(typeof(MyAttributeImpl)) { _ids = ids; } private class MyAttributeImpl : IActionFilter { private readonly ILogger _logger; public MyAttributeImpl(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger<MyAttribute>();

How do I add a parameter to an action filter in asp.net?

老子叫甜甜 提交于 2019-12-29 05:16:04
问题 I have the following filter attribute, and i can pass an array of strings to the attribute like this [MyAttribute("string1", "string2")] . public class MyAttribute : TypeFilterAttribute { private readonly string[] _ids; public MyAttribute(params string[] ids) : base(typeof(MyAttributeImpl)) { _ids = ids; } private class MyAttributeImpl : IActionFilter { private readonly ILogger _logger; public MyAttributeImpl(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger<MyAttribute>();

How to add link parameter to asp tag helpers in ASP.NET Core MVC

ぐ巨炮叔叔 提交于 2019-12-29 03:11:32
问题 I have a lot of experience with ASP.NET MVC 1-5 . Now I learn ASP.NET Core MVC and have to pass a parameter to link in page. For example I have the following Action [HttpGet] public ActionResult GetProduct(string id) { ViewBag.CaseId = id; return View(); } How can I implement the link for this action using tag helpers? <a asp-controller="Product" asp-action="GetProduct">ProductName</a> 回答1: You can use the attribute prefix asp-route- to prefix your route variable names. Example: <a asp

What could cause `UserManager` to return the wrong user?

本小妞迷上赌 提交于 2019-12-28 19:28:09
问题 Something rather scary is happening on my ASP.NET Core 2.1.0 MVC site. While I was browsing, all of a sudden it shows I am logged in as a different user (who also happens to be browsing the site at that time). I can't pinpoint whether there is a specific use case that triggers this, but this has happened twice now. Navigating to other pages still shows I am logged in as the other user. It even seems I take over the claims of the user I am incorrectly logged in as. My question is: what could

How to get bin folder in ASP.NET Core 1.0

邮差的信 提交于 2019-12-28 12:02:52
问题 With asp.net core 1.0 There are lots of functionality added. But there is not way to get Bin Folder path. Can anyone please know how we can get the bin folder path for asp.net core 1.0 application. 回答1: Well, the bin folder does exists but it is moved to artifacts folder next to the solution file. Since ASP.NET Core RC 1 compiles everything in memory, you will find empty bin folder. But if you set "Produce output on build" option to true (Right click Project file -> Properties and Build tab)

Self referencing loop from Newtonsoft JsonSerializer using Entity Framework Core

大城市里の小女人 提交于 2019-12-28 07:07:11
问题 I've encountered the error: JsonSerializationException: Self referencing loop detected for property 'Subject' with type 'Project.Models.Subject'. Path 'data[0].Totals'. It occurs when I load a View with a dataGrid populated by an IEnumerable<Subject> model. The Grid is a DevExtreme DataGrid bound to the View's model like this: @(Html.DevExtreme().DataGrid() .DataSource(Model) .Paging(paging => { paging.Enabled(true); paging.PageIndex(0); paging.PageSize(20); }) .Columns(columns => { columns

How do I use a standard class library in MVC6?

微笑、不失礼 提交于 2019-12-28 06:26:26
问题 Is there a reasonably convenient way to include a standard class library in MVC6? I thought the standard add reference dialog could create a wrapper but I'm not having any luck. Publishing it as a nuget package seems pretty inconvenient for ongoing development debugging. If there isn't a wrapper is there a built in way to convert the standard class library to the new type? 回答1: I have seen a couple of different approaches so far (using the dnu utility or adding references using VS). It is

How to implement a “pure” ASP.NET Core Web API by using AddMvcCore()

谁说我不能喝 提交于 2019-12-28 04:50:09
问题 I've seen a lot of ASP.NET Core Web API projects that use the default AddMvc() service without the realizing that using AddMvcCore() is a superior option due to the control over services. How exactly do you implement an ASP.NET Core Web API by using AddMvcCore() and why is it better? 回答1: What is the difference between AddMvc() and AddMvcCore() ? The first thing key thing to understand is that AddMvc() is just a pre-loaded version of AddMvcCore() . You can see the exact implementation of the

MVC Controller Action only receiving nulls from AJAX

丶灬走出姿态 提交于 2019-12-25 19:04:55
问题 I have an ajax call that passes data for two parameters to a controller action. The action is called, but the parameters for the action always have null values (in this case the integer is its default of value of 0). I have made sure to check the packets sent by the ajax call and I do see the correct values I intend to send with the correct parameter/attribute names in stringified JSON. Here is the Controller Action: [HttpPost] public IActionResult Summary(int courseID, String test) { using