asp.net-core-mvc

Use MVC Router to determine if route exists

删除回忆录丶 提交于 2019-12-11 06:35:10
问题 Is it possible to use the ASP.NET Core MVC Router to determine, if a redirect to a specific location might be successfull? I'd like to inject the MVC Router and just ask it, if the route I want to use exists at all, but I'm struggling finding the correct classes to inject and did not see any method of use in the MVCRouter. I would also be okay in overriding the default router and extend it with the neccessary methods. 回答1: One way to do this would be to inject IActionSelector to your

Modeling mongodb stored referenced relationships in .net core

不羁岁月 提交于 2019-12-11 06:27:22
问题 I'm new to mongo and I'm looking for some guidance on best practices when dealing with referenced relationships and modeling them in .net core. Yes, it's the usual "joins in mongodb??" question. But I haven't found a good answer to this. To make this simple, lets say I've got a simple API i'm building out with controllers to manage users and accounts. In mongo there are two collections, Accounts and Users. Users belong to their parent Account. I don't want to go the embedded document route in

ASP.NET Core routing with RouteValueDictionary

左心房为你撑大大i 提交于 2019-12-11 06:15:37
问题 I need to create Tag helper to generate url from form with multi select. I remember, in older mvc I could use something like this: var i = 0; foreach (var attribute in PaginatorFilterItems) { foreach (var attributeFilter in attribute.Value) { routeValues.Add($"{attribute.Key}[{i++}]", attributeFilter.ToString()); } i=0; } Now, I can use it in Url.Action(..., ..., routeValues) helper and got something like this: ?str=val1&str=val2 etc. But in dotnet core I get some escape sequence. I'm not

Trigger TagHelper from another TagHelper

落爺英雄遲暮 提交于 2019-12-11 06:03:50
问题 I would like to trigger the stock ScriptTagHelper (view source on GitHub) so that it would emulate the asp-append-version="true" attribute. I know that the proper way to use this is to just change from this: <script src="somefile.js"></script> to this: <script src="somefile.js" asp-append-version="true"></script> This process is very similar for versioning CSS includes and images ( LinkTagHelper and ImageTagHelper ). Since I have a lot of included scripts, stylesheets, and images, I would

ASP.Net Core saving base64 string

倾然丶 夕夏残阳落幕 提交于 2019-12-11 06:01:56
问题 I have a Image model: public class Image { [Key] public long ImagelId { get; set; } public string base64 { get; set; } } Which I use like following: public class CoreGoal { [Key] public long CoreGoalId { get; set; } [Required] public string Title { get; set; } public virtual ICollection<Image> Images { get; set; } public CoreGoal() { } } I am using MySql database. I intend to store possibly multiple images as base64 strings against each CoreGoal. Whenever I make a POST request with base64

How to require parameters in action

拥有回忆 提交于 2019-12-11 05:58:27
问题 I want to validate that a parameter is present in the action. public string PorCarrera([Required] DateTime fechaDesde, [Required] DateTime fechaHasta, string carrera = null) { return InformacionInscripcionesViewModel.GetTotalesInscripcionesPorCarrera(fechaDesde, fechaHasta, carrera); } I would expect the framework to throw a BadRequest when calling the action without parameters but it is not happening. All examples talk about modelState.IsValid but I don't have any model that represents this

Register controller in another assembly in ASP.NET MVC Core 1.1

冷暖自知 提交于 2019-12-11 05:54:48
问题 I'm trying to make a shared library for a .NET MVC Core 1.1 app that contains a controller that needs to be registered in the host MVC app. I've found some examples of this for earlier versions of .NET Core but none of them seem to work in the current release. This was the approach that looked most promising: services .AddMvc() .AddApplicationPart(typeof(OtherAssembly.Controller).GetTypeInfo().Assembly) .AddControllersAsServices(); I have not altered the standard routes so they still look

ASP.Net Core MVC RedirectToAction is appending controller name in front of returnUrl

别等时光非礼了梦想. 提交于 2019-12-11 05:49:27
问题 I am working on a ASP.Net core, MVC 6 application. I have an AppControler as my initial controller and if a user tries to go to an action that has an [Authorize] attribute, I redirect to my AuthController for the login, passing in the returnUrl for the return. Once authenticated, I use ... return RedirectToAction(returnUrl). In debug, I can see that the returnUrl string is set to /App/Timesheets. However, in the browser address bar, it has an address of http://localhost:49940/Auth/%2FApp

Setting Environment When Publishing An MVC 6 Web App

孤街醉人 提交于 2019-12-11 05:48:32
问题 I'm testing out development in Dot Net Core, and I'm up to deploying my application. For now I've done a simple file publish to my local PC, and then copied the files onto the remote server. When I view the website, I can see that it is running in either the Staging or Production environment due to me being served minified files (Which are specified in the view). However I'm struggling to find any documentation to say where or how this environment can be specified at publish time. Even if I

MVC 6 integrated help missing in visual studio 2015

纵然是瞬间 提交于 2019-12-11 05:34:37
问题 This is such a pathetic question to ask here, but I'm out of ideas. I've recently had cause to start experimenting with a Web API project using MVC 6 in Visual Studio 2015. It's all very new to me, and I've wanted to look at the associated help for a number of classes, properties, attributes, and so on. But the F1 integrated help, local or web based, always comes up "cannot find". Even on a simple/central class like Controller, it looks up the help id MICROSOFT.ASPNET.MVC.CONTROLLER and finds