asp.net-core-mvc

What is the equivalent of System.Web.Mvc.Html.InputExtensions in ASP.NET 5?

允我心安 提交于 2019-12-23 12:04:02
问题 What is the ASP.NET 5 equivalent of System.Web.Mvc.Html.InputExtensions as used in ASP.NET 4? See example below: public static class CustomHelpers { // Submit Button Helper public static MvcHtmlString SubmitButton(this HtmlHelper helper, string buttonText) { string str = "<input type=\"submit\" value=\"" + buttonText + "\" />"; return new MvcHtmlString(str); } // Readonly Strongly-Typed TextBox Helper public static MvcHtmlString TextBoxFor<TModel, TValue>(this HtmlHelper<TModel> htmlHelper,

Execute .bat file at end of VS2017 Asp.Net Core publish action?

走远了吗. 提交于 2019-12-23 10:54:39
问题 In Visual Studio 2017 when publishing an Asp.Net Core Website using the File System publish method I want to trigger the execution of a .bat file after the publish operation copied the files to the output directory. I have learned that the settings for the publish operation are stored by Visual Studio in the project's Properties/PublishProviles directory in a .pubxml file. So in may case the file is FolderProfile.pubxml and it currently looks like this: <?xml version="1.0" encoding="utf-8"?>

How to use Property Injection in MVC Core and AutoFac

北城余情 提交于 2019-12-23 10:51:40
问题 I can use Constructor Parameter Injection easily In MVC Core. But Property Injection is not supported.I try use AutoFac but fail too. So how to use Property Injection in MVC Core. Here is the code with AutoFac services.AddMvc(); ContainerBuilder builder = new ContainerBuilder(); builder.RegisterType<Test2>().As<ITest>(); builder.RegisterType<HomeController>().PropertiesAutowired(); builder.Populate(services); var container = builder.Build(); //The following code works HomeController test2 =

ASP.NET Core Route not working

别来无恙 提交于 2019-12-23 10:06:15
问题 The Routers are configured this way: app.UseMvc(routes => { routes.MapRoute( name: "api", template: "api/{action}/{id?}"); }); app.UseMvc(routes => { routes.MapRoute( name: "spa-fallback", template: "{*url}", defaults: new { controller = "Home", action = "Index"}); }); The controller I action I am trying to request looks like this: // GET api/values/5 [HttpGet("{id}")] public string Get(int id) { return "value" + id; } When I request http://localhost:54057/api/values/get, I get back "value0".

IEnumerable<> is defined in an assembly that is not referenced - new NuGet Class Library project

六月ゝ 毕业季﹏ 提交于 2019-12-23 09:51:45
问题 I'm using VS2015 Community, I have .NET 4.6.01040 installed and I followed these instructions to install ASP.NET 5. I want to start migrating a site from MVC5 to MVC6 all the other updates that came with it, so I started with the Entity Class library project that holds my Data model. This is how my project.json file looks like: { "version": "1.0.0-*", "description": "test.Entities Class Library", "authors": [ "me" ], "tags": [ "" ], "projectUrl": "", "licenseUrl": "", "frameworks": { "net461"

“The type or namespace name could not be found” in ASP.NET Core 1.0 RC2

社会主义新天地 提交于 2019-12-23 09:42:04
问题 I'm currently trying ASP.NET Core 1.0 RC2. I've created it as a .NET Framework project (as opposed to a .NET Core project) and added references to our Models library, using .NET Framework 4.5, via a project reference: "frameworks": { "net46": { "dependencies": { "Project.Core": { "target": "project" }, "Project.DataAccess": { "target": "project" }, "Project.Encryption": { "target": "project" }, "Project.Models": { "target": "project" }, "Project.Resources": { "target": "project" } } } }, Now

Migrating ASP.NET MVC 5 bundling “versions” to MVC 6

。_饼干妹妹 提交于 2019-12-23 09:31:59
问题 The bundling feature is excluded from MVC 6 and the suggested method is to do bundling using gulp tasks. Using bundling we used to get a random string at the end of the included css/javascript file url(s). This string was very important because once you changed anything in your css/javascript then a new string would be generated which would force browsers to load the new version(s) of the file(s). So if you had 3 css files they would be bundled into one and they would look like this: <link

There was an error running the selected code generator: Could not load file or assembly Microsoft.EntityFrameworkCore, version = 2.0.1.0

强颜欢笑 提交于 2019-12-23 09:15:49
问题 When I was creating a Controller and a View by MVC Controller with views, using Entity Framework I got an error. The Error is: There was an error running the selected code generator: 'Could not load file or assembly Microsoft.EntityFrameworkCore, version = 2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' the located assembly's manifest definition does not match the assembly reference Creating MVC Controller with views, using Entity Framework: How can I solve this problem? I use

Pass current transaction to DbCommand

我是研究僧i 提交于 2019-12-23 08:50:00
问题 I'm working on a project using ASP.NET Core 2.1 and EF Core 2.1. Although most of queries and commands use EF, some units needs to call stored procedures directly. I can't use FromSql , because it needs results set based on entity models. Let's assume we have these methods: public Task CommandOne(DbContext context) { Entity entity = new Entity { Name = "Name" }; context.DbSet<Entity>().Add(entity); return context.SaveChangesAsync(); } public async Task CommandTwo(DbContext context) {

How access ViewContext from helper/service, @injected via ViewImports

天涯浪子 提交于 2019-12-23 08:30:20
问题 I'm writing helper class and inject in in _ViewImports with @inject HtmlHelperInject.TestHelper TestHelper And register in Startup.ConfigureServices with services.AddTransient<TestHelper>(); How can I obtain ViewContext in this helper class? I tried injecting via controler - not working, via [ViewContext] attribute on property - not working. 回答1: As of right now (beta8) the way to do this is to implement... wait for it... ICanHasViewContext . This interface adds the following contract: void