razor-pages

Render a Razor Page to string

淺唱寂寞╮ 提交于 2019-12-03 19:01:21
问题 Problem: I need to render a Razor Page partial to a string. Why I want this: I want to create a controller action that responds with JSON containing a partial view and other optional parameters. Attempts: I am familiar with the following example that renders a View to a string: https://github.com/aspnet/Entropy/blob/dev/samples/Mvc.RenderViewToString/RazorViewToStringRenderer.cs However, it is not compatible with Pages, as it only searches in the Views directory, so even if I give it an

Download file to browser using .NET Core Razor Pages

主宰稳场 提交于 2019-12-03 09:32:01
Using ASP.NET Razor Pages, I am trying download a file to the browser. From the Page(html), using a link like this works fine: href="/DownloadableFiles/testB.csv" download="newname">Download Link However, I want to initiate the download from the code-behind or ViewModel so it can be dynamic as to what the filename is, I also need to inspect the file first, etc. In ASP.NET MVC core, (not RazorPages) you can download a file in code using: return File(memory, GetContentType(path), Path.GetFileName(path)); But return File is not supported in Razor Pages. Bob Gundeck pitaridis is correct, return

Navigation menu on the left side with close and open button in ASP.NET Core razor pages application

杀马特。学长 韩版系。学妹 提交于 2019-12-02 11:28:47
问题 I am using razor pages for my application. I tried to move the navigation menu from top to left side. I followed the steps mentioned in this link how to create sidebar menu in bootstrap that stays? since I want my menu to be exactly as shown in that link. But I couldn't achieve the result. Something about simple-sidebar.css is mentioned in the link but I would like to know where exactly and how it should be added to my razor pages project. What changes should I make to move my navigation menu

ef core one to many relationship throw exception Cannot add or update a child row

丶灬走出姿态 提交于 2019-12-02 10:48:23
问题 My Shop and Product entities have a one to many relationship, please see my models public class Product { public int ID { get; set; } public string Name { get; set; } public string Tag { get; set; } public string Brand { get; set; } public string Place { get; set; } public int ShopID { get; set; } public Shop Shop { get; set; } } public class Shop { public int ID { get; set; } public string Name { get; set; } public string Comment { get; set; } public string Number { get; set; } public

ef core one to many relationship throw exception Cannot add or update a child row

房东的猫 提交于 2019-12-02 07:24:57
My Shop and Product entities have a one to many relationship, please see my models public class Product { public int ID { get; set; } public string Name { get; set; } public string Tag { get; set; } public string Brand { get; set; } public string Place { get; set; } public int ShopID { get; set; } public Shop Shop { get; set; } } public class Shop { public int ID { get; set; } public string Name { get; set; } public string Comment { get; set; } public string Number { get; set; } public ICollection<Product> Products { get; set; } } public class ShopContext : DbContext { public ShopContext

Navigation menu on the left side with close and open button in ASP.NET Core razor pages application

好久不见. 提交于 2019-12-02 06:28:31
I am using razor pages for my application. I tried to move the navigation menu from top to left side. I followed the steps mentioned in this link how to create sidebar menu in bootstrap that stays? since I want my menu to be exactly as shown in that link. But I couldn't achieve the result. Something about simple-sidebar.css is mentioned in the link but I would like to know where exactly and how it should be added to my razor pages project. What changes should I make to move my navigation menu from top to left side as shown in the link that I mentioned since it is not working for my razor pages

Cannot pass data with ajax to razor pages

不羁的心 提交于 2019-12-02 04:47:22
I am trying to send some data to razor page method, but the problem is that in method it takes always as 0 . Heres the code: Razor Page: public IActionResult OnGetProducts(int page) { var products = _productRepository.GetProducts(); decimal pagesInDecimal = (products.Count() / 18); var totalPages = pagesInDecimal % 1 == 0 ? pagesInDecimal : pagesInDecimal + 1; products = products.Skip((page - 1) * 20).Take(20); return new JsonResult(new { totalPages = totalPages, products = products }); } Ajax: getProducts(1); function getProducts(page) { $.ajax({ type: 'GET', url: "/Products", contentType:

TempData not working when published to Azure

不羁岁月 提交于 2019-12-01 19:10:31
I have a site I'm playing with to get the hang of Razor Pages. I have a weird situation I'm unsure what is happening or how to resolve. I'm using [TempData] to pass a message on redirect. The app works perfectly locally. Once published to Azure I add a new item and the item is added, I'm redirected to the index page but I never see the TempData message. Here is my Index page: public class IndexModel : PageModel { private readonly TheFishRoom_MVC_Core.Data.FishRoomDbContext _context; public IndexModel(TheFishRoom_MVC_Core.Data.FishRoomDbContext context) { _context = context; } public IList

Localized page names with ASP.NET Core 2.1

偶尔善良 提交于 2019-12-01 06:55:58
问题 When create a Razor page, e.g. "Events.cshtml", one get its model name set to @page @model EventsModel where the page's name in this case is "Events", and the URL would look like http://example.com/Events To be able to use page name's in Norwegian I added the following to the "Startup.cs" services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddRazorPagesOptions(options => { options.Conventions.AddPageRoute("/Events", "/hvaskjer"); options.Conventions.AddPageRoute("

How to return a PartialView from Core 2 RazorPage ViewModel Handler

二次信任 提交于 2019-12-01 04:18:58
In Asp.Net MVC, you can easily return a partial view by doing the following: return PartialView("ModelName", Model); How is this done on a RazorPage ViewModel Handler? TechFisher I figured this out. It is not nearly as straight forward as it is in MVC. You have to create an empty ViewDataDictionary() and then set its Model property to the partial's populated model. View Model / Handler public async Task<IActionResult> OnGetAsyncUpdateSearchResults(DateTime startDate, DateTime endDate, string selectedTypes) { int[] types = selectedTypes.Split(",").Select(x => int.Parse(x)).ToArray(); var