asp.net-core-mvc

How do I paginate through a ViewModel in MVC CORE?

扶醉桌前 提交于 2019-12-10 21:14:03
问题 In the MVC CORE demo from https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/sort-filter-page the Contoso university sample program uses a model on the paginating example page var students = from s in _context.Students select s; return View(await PaginatedList<Student>.CreateAsync(students.AsNoTracking(), page ?? 1, pageSize)); while the viewmodel gets passed back as a complete entity like this var viewModel = new InstructorIndexData(); viewModel.Instructors = await _context.Instructors

Where are jQuery-UI scripts stored in MVC6 project?

回眸只為那壹抹淺笑 提交于 2019-12-10 20:33:15
问题 I'm starting with MVC6 and I'm trying to use some jQuery-UI elements. After installing the package, I cannot find the script files of jQuery-UI. While lot of tutorials on the internet tell that the files should be stored in Scripts folder (for example: <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.min.js")"></script> ), it seems that it isn't the case with MVC6. I saw this question (How to get JQuery-UI to work with ASP.NET MVC6?) in which the file is retrieved from jQuery site :

Return a view with ASP.NET Core API

坚强是说给别人听的谎言 提交于 2019-12-10 20:23:24
问题 I am writing an ASP.NET Core API and I was wondering how I could return a View in a Controller. The goal is to provide a documentation on this page. What I have tried is to create a Controller class, that returns a ViewResult, like below: [Route("api/[controller]")] public class HomeController : Controller { [HttpGet] public IActionResult Get() { return View(); } } Then, I have Created a simple view named Index.cshtml in a View/Home repository. When I launch the app with /api/home, it does

Branching ASP.NET Core Pipeline Authentication

試著忘記壹切 提交于 2019-12-10 20:11:55
问题 My application is currently using Basic authentication but I want to transition to OAuth, so there will be a short period where both types of authentication need to be used. Is there some way to branch my ASP.NET Core pipeline like so: public void Configure(IApplicationBuilder application) { application .Use((context, next) => { if (context.Request.Headers.ContainsKey("Basic")) { // Basic } else if (context.Request.Headers.ContainsKey("Authorization")) { // OAuth } return next(); })

DllNotFoundException in ASP5/MVC6 while instantiating an object (using the WorkItemStore Class)

有些话、适合烂在心里 提交于 2019-12-10 19:36:16
问题 I'm trying to instantiate the WorkItemStore Class in my MVC 6 (dnx 4.5) web app but I'm getting the following DllNotFoundException error. An exception of type 'System.DllNotFoundException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll but was not handled in user code Additional information: Unable to load DLL 'Microsoft.WITDataStore32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) This is my code. 200Uri = new Uri("http:/

.net core and ef core sql server error provider: SQL Network Interfaces, error: 8 - Protocol not supported

不羁的心 提交于 2019-12-10 19:26:38
问题 I've been trying to develop a new application using .net core in MacOsX using a SQL Server database, but i'm having some problems with the connection because i'm getting the following error: fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HKTRSSNBPQOP": An unhandled exception was thrown by the application. System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not

RedirectToAction gets ignored

梦想与她 提交于 2019-12-10 19:09:32
问题 I am using ASP.NET 5. Using the browser Chrome. My Controller has the following Action Method public async Task<IActionResult> Index() { return View(); } [HttpPost] public IActionResult DoSomething() { //do something return RedirectToAction("Index"); } When I run http://localhost:59693/MyArea/MyController/DoSomething via a POST in Index and have a breakpoint over the line return RedirectToAction("Index"); it just ignores the line and goes to the next line without calling the Index action

ASP.Net application interfering with remote host Let's Encrypt (via Plesk) installation?

三世轮回 提交于 2019-12-10 18:50:14
问题 So, to install Let's Encrypt SSL cert, I head over to my Plesk account, pick a domain or subdomain and click on Let's Encrypt then I only have a field to put in an email address, and a button to install. To install, Let's Encrypt sends my site an HTTP request: GET /.well-known/acme-challenge/n9cD8Lpv-woEU73NhCUdFyqOYMc5hrANF_byoiaYrZc - HTTP/1.1 If I create a fresh 'site' through Plesk, and install the cert, that GET request get's a nice 200 response and the SSL cert installs fine. However, I

ASP.NET 5 MVC 6: How to configure startup to send a html file when not on any mvc route

与世无争的帅哥 提交于 2019-12-10 18:48:47
问题 I'm building a SPA application using React-Router to handle the front-end routing. I'm trying to configure the ASP.NET 5 Startup.cs file to use MVC but when a route does not match any of my API routes to send the index.html file so that it will be able to handle react-routers browser history implementation as stated here. So far i've only been able to get it to send the index.html file when on the default route, i.e. nothing after the localhost:3000. My Startup Configure method so far. Thank

EF 7 (Core). Create DBContext like AddTransient

瘦欲@ 提交于 2019-12-10 18:48:24
问题 According to documents when I configure DbContext like below DI register it in scope (per http request) services.AddEntityFramework() .AddSqlServer() .AddDbContext<DBData>(options => { options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]); } ); The problem appears when I am trying to access it in another thread. public class HomeController : Controller { private readonly DBData _context; public HomeController(DBData context) { _context = context; } public