asp.net-core-mvc

How to bind an Array in MVC Core

主宰稳场 提交于 2019-12-06 05:51:17
问题 I try to bind an object like this in a Action public class MonthDataViewModel { public int Year { get; set; } public int Month { get; set; } public IEnumerable<MoneyDataItemViewModel> MoneyCosts { get; set; } } public class MoneyDataItemViewModel { public string Title { get; set; } public decimal Cost { get; set; } } Is that possible? How do i design the form? I try a few times but the property MoneyCosts won't be bind , and this is the data i submited: Year=2016 Moneh=8 MoneyCosts.Title=ABC

ASP.NET MVC 6 application's virtual application root path

China☆狼群 提交于 2019-12-06 05:00:38
How do I get the virtual root path of the application on the server? In another words: how can I do the following in ASP.NET MVC 6? HttpContext.Current.Request.ApplicationPath What you need can be achieved with @Url.Content("~/") , which will map "~" to your virtual application root path. Having a look at the source code , it seems to do so using the HttpContext.Request.PathBase property: public virtual string Content(string contentPath) { if (string.IsNullOrEmpty(contentPath)) { return null; } else if (contentPath[0] == '~') { var segment = new PathString(contentPath.Substring(1)); var

How to inject dependencies into models in asp.net core?

北城余情 提交于 2019-12-06 04:50:36
问题 Let's say I have a controller action that looks like this: [HttpPost] public async Task<IActionResult> Add([FromBody] MyModel model){ await model.Save(); return CreatedAtRoute("GetModel", new {id = model.Id}, model); } In order to get model.Save to work, it needs some dependencies: public class MyModel{ private readonly ApplicationDbContext _context; public MyModel(ApplicationDbContext context){ _context = context; } public async Task Save(){ // Do something with _context; } } As of right now

what is the difference between use dbset and mappers in EF7

家住魔仙堡 提交于 2019-12-06 04:39:16
问题 I started to work with .net core and Entityframework 7 in Onion Architecture ! i readed this tutorial and i think its best case for learning following subject. but one part of this tutorial made a big question inside my brain. like what you see at this linked page; at Data Layer we have some classes which are our model!! public class User : BaseEntity { public string UserName { get; set; } public string Email { get; set; } public string Password { get; set; } public virtual UserProfile

dotnet exec needs a managed .dll or .exe extension while adding Entity Framework Core (1.1.0) Migrations

北城余情 提交于 2019-12-06 04:24:54
Error Message: PM> Add-Migration InitialDatabase dotnet exec needs a managed .dll or .exe extension. The application specified was 'C:\Users\xxxxxx\documents\visual studio 2017\Projects\TheWorld\src\TheWorld\bin\Debug\netcoreapp1.0\TheWorld.runtimeconfig.json' Process finished with non-zero exit code PM> Visual Studio Version: 2017 RC Project Dependencies : Error Screenshot : I had the same problem. The only thing I had to do is changing the Target Framework in the Project properties. Changing the framework version I hope this helps. Shiju Narayan In VS2017RC - All I had to do was install

Hooking into razor page execution for ASP.Net Core

我只是一个虾纸丫 提交于 2019-12-06 04:07:34
I'm trying to hook into the ExecuteAsync() call that renders a razor page using my CUSTOM view page (that inherits from RazorPage ). In the RazorPage class there is this abstract method: public abstract Task ExecuteAsync(); That method gets called within the output generated by razor when parsing a .cshtml file (view). Obviously, I cannot just override it because mine would never get called from the view that gets generated, which also overrides this method (though that would be nice, and solve at least part of the problem). Is there any special razor tricks in .Net core where I can intercept

.NET Core forward a local API form-data post request to remote API

牧云@^-^@ 提交于 2019-12-06 03:32:06
问题 I have an AJAX form which post a form-data to a local API url: /api/document . It contains a file and a custom Id. We simply want to take the exact received Request and forward it to a remote API at example.com:8000/document/upload . Is there a simple way of achieve this "forward" (or proxy?) of the Request to a remote API using Asp.NET Core? Below we had the idea to simply use Web API Http client to get the request and then resend it (by doing so we want to be able to for example append a

TagHelper cached output by calling GetChildContentAsync() and Content.GetContent()

半城伤御伤魂 提交于 2019-12-06 03:31:45
According to this article if we use several tag helpers(targeted to the same tag) and in each of them we will use await output.GetChildContentAsync() to recieve html content we will come to the problem with cached output: The problem is that the tag helper output is cached, and when the WWW tag helper is run, it overwrites the cached output from the HTTP tag helper. The problem is fixed by using statement like: var childContent = output.Content.IsModified ? output.Content.GetContent() : (await output.GetChildContentAsync()).GetContent(); Description of this behaviour: The code above checks to

User is authenticated but where is the access token?

假装没事ソ 提交于 2019-12-06 03:08:34
问题 I have a web Application which authenticates a user to an Identity Server 4, using an implicit client. I need the access token for this user so that I can make a call to another API. To be clear: I have an identity Server. Created using Identity server 4. I have the web app in question created in Asp .net core mvc. API created in .net core. The Web application authenticates the user against the identity server. Once they are authenticated we use bearer tokens to access the API. services

Access ASP.NET 5 View Component via URL

元气小坏坏 提交于 2019-12-06 03:01:07
问题 With the replacement of partial views in ASP.NET 5 with view components, how does one access the view components via URL? I know you call them like... @Component.Invoke("SomeList", 1) ...but what if you need to have like ajax paging, where you need a callback url to request the next set to be displayed in a partial view? So, a user can click "Load More" and it loads more from a 'partial view'. 回答1: You cannot access a view component from a URL directly. A view component is just a component of