asp.net-core-mvc

Typeconverter does not work in asp.net core

坚强是说给别人听的谎言 提交于 2019-12-04 02:59:46
问题 I have Amount stored in the database as decimal . I want to show that value on UI with thousand separator. I can add [DisplayFormat(DataFormatString = "{0:N2}", ApplyFormatInEditMode = true)] attribute on amount property and that would display number with thousand separator however when i POST the value back to server, the MVC model binding would not work because of commas. I have created a custom type converter that converts from decimal to string and then string to decimal public class

Is it possible to serve static files from outside the wwwroot folder?

落爺英雄遲暮 提交于 2019-12-04 02:52:27
I have an ASP.NET MVC 6 project with the following structure: project/ wwwroot/ custom/ project.json I want to serve files from custom as it if was a virtual folder into http://localhost/custom without having to copy them during development. Is it possible to do this in vNext without a virtual folder from IIS (say, using the StaticFile middleware)? David Driscoll You can set the file provider on the options object when using the middleware. app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(@"C:\Path\To\Files"), RequestPath = new PathString("/somepath") }) See

VS 2017 always times out debugging an MVC Core website on IIS Express profile

拟墨画扇 提交于 2019-12-04 02:08:49
On a plain vanilla, scaffolded ASP.NET Core MVC web app, with a DbContext registered in the DI container, whenever I hit F5 after 30-60 seconds, I get the error message: Unable to start program ' http://localhost:60175/ '. Operation timed out. The home page in an index view, whose action gets all employees from a localhost SQL Server db. The project is already built, so the initial build for debug is quite quick, and doubtfully the cause of the delay. If I run without debugging, I get the home page up in 30 - 40 seconds. Just what is timing out, and can I set that timeout? Or is there anything

How to invoke a View Component from controller

折月煮酒 提交于 2019-12-04 01:55:14
Is it possible to invoke a View Component from controller and render it to a string? I am really looking for some code example for this. Any help will be much appreciated. You can do that but you have to apply following thing as It is render by DefaultViewComponentHelper. You have to create instance of this and to create that you need IViewComponentSelector and IViewComponentInvokerFactory. To do this I have done following thing. public class HomeController : Controller { Microsoft.AspNet.Mvc.DefaultViewComponentHelper helper = null; Microsoft.AspNet.Mvc.Razor.RazorView razorView = null;

How important is the global.json and src folder?

≡放荡痞女 提交于 2019-12-04 01:53:34
In VS 2015, when you create a new MVC 6.0 application using this approach: File-->New-->Project-->ASP.NET Web Application-->ASP.NET 5 Preview Templates You end up have the following file structure on disk: artifacts src MyProject.sln global.json Instead if I decide to create a blank solution first like so: File-->New-->Project-->Other Project Types-->Visual Studio Solutions-->Blank Solution And start adding a new ASP.NET Web Application project to this solution; you end up having a file structure that doesn’t have a global.json file and no src folder. According to the documentation , the

ASP.NET MVC 6 handling errors based on HTTP status code

左心房为你撑大大i 提交于 2019-12-04 01:28:26
I want to display different error messages for each status code e.g: 400 Bad Request 403 Forbidden 500 Internal Server Error 404 Not Found 401 Unauthorized How can I achieve this in the new ASP.NET MVC 6 applications? Can I do this using the built in UseErrorHandler method? application.UseErrorHandler("/error"); Also, I noticed that even with the above handler, entering a non-existent URL e.g. /this-page-does-not-exist, causes an ugly 404 Not Found error page from IIS. How can this also be handled? In MVC 5 we have had to use the system.web customerrors section for ASP.NET and the system

Where is HtmlEncode in Asp.NET 5

不羁的心 提交于 2019-12-04 01:17:36
I have a custom IHtmlHelper extension method that uses TagBuilder and returns an HtmlString . I can no longer pass tagBuiler.ToString() to the HtmlString constructor as that just returns the typename now. I see I can use the tabBuiler.WriteTo(TextWriter, IHtmlEncoder) method but I don't know exactly how to get my hands on an object that implments IHtmlEncoder . I see encoders in both System.Text.Encodings.Web and Microsoft.Framework.WebEncoders . But the types in the two namespace don't seem to play well together. HtmlEncoder in Microsoft.Extensions.WebEncoders.Core is just a wrapper around

Scaffold-DbContext creating model for table without a primary key

社会主义新天地 提交于 2019-12-04 00:16:36
I am trying to create DBcontext and corresponding model for a particular table in ASP.NET core MVC application. This table doesn't have any primary key. I am running following Scaffold-DbContext command- Scaffold-DbContext "Server=XXXXX;Database=XXXXXXX;User Id=XXXXXXX;password=XXXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t TABLE_NAME -force -verbose In Package Manager Console, I can see this verbose output- ............... ............... Unable to identify the primary key for table 'dbo.TABLE_NAME'. Unable to generate entity type for table 'dbo.TABLE_NAME'. My

Localization in ASP.Net core MVC not working - unable to locate resource file

萝らか妹 提交于 2019-12-03 23:56:56
In trying to localize my application, I've followed the steps here: https://docs.asp.net/en/latest/fundamentals/localization.html Here is my code: Startup.cs public List<IRequestCultureProvider> RequestCultureProviders { get; private set; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddLocalization(options => options.ResourcesPath = "Resources"); services.AddMvc() .AddViewLocalization(options => options.ResourcesPath = "Resources") .AddDataAnnotationsLocalization(); services

How to deploy ASP.NET Core UserSecrets to production

人走茶凉 提交于 2019-12-03 23:46:16
I followed the Safe storage of app secrets during development guide over on the asp.net docs during development but it does not describe how to use it when publishing to another machine for QA, Production, etc. What I figured it would do was insert them into the appsettings.json during publish but it does not. I ended up having to place my SendGrid keys and other sensitive information directly into the appsettings.json which really defeats the purpose of the app secrets. Is using app secrets the best way or is there another way to store API keys and SQL user/passwords in my configs? Don't use