razor-pages

.NET Core 3.0 - Preview 2 - Razor views don't automatically recompile on change

大憨熊 提交于 2019-12-17 22:26:18
问题 According to https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.0 by default razor views should recompile on change on local environments for asp.net core 3.0. However, my project doesn't do this locally. If I change a view and refresh when I'm debugging locally, the change does not reflect. I have to stop the solution, re-run, and then see the change. I am doing this on a default ASP.NET Core Web Application template on Visual Studio 2019 with asp.net

Mocking User ClaimsPrincipal for Razor Pages Unit Test

混江龙づ霸主 提交于 2019-12-14 03:57:22
问题 I have an issue regarding writing a unit test for a Razor Page combined with MVVM. I want to test an OnPostAsync() method from Razor, however this method will call two more methods which require a ClaimsPrincipal User. I can't give the User as a parameter for these methods from within my test however. My current test method: [Test] public void MakeBookingTest() { //Arrange var optionsbuilder = new DbContextOptionsBuilder<ApplicationDbContext>(); optionsbuilder.UseInMemoryDatabase(databaseName

How can you clear a bound property on a Razor Page's model when POSTing?

好久不见. 提交于 2019-12-13 19:18:36
问题 I have a property that is bound to an input field: <input id="name" asp-for="ContactName" name="ContactName" placeholder="Name" type="text" style="width: 200px !important;" autofocus> [BindProperty] public string ContactName { get; set; } When I POST, I tried clearing the ContactName property by setting it to NULL or string.Empty, but it doesn't work. What's the proper way to clear out this field? 回答1: The "proper" way is to follow the PRG (Post-Redirect-Get) pattern. The values of your

How to replace MVC HomeController/Index redirects with RazorPages routings?

。_饼干妹妹 提交于 2019-12-13 19:04:50
问题 I'm migrating from ASP MVC Classic to ASP Razor Pages. Only one controller left to "migrate": HomeController public class HomeController : Controller { UserManager<WebUser> _userManager; public HomeController(UserManager<WebUser> _userManager) { this._userManager = _userManager; } [Authorize] public async Task<IActionResult> Index() { var user = await _userManager.GetUserAsync(User); if (user == null) { return RedirectToPage("/Account/Login", new { area = "WebUserIdentity" }); } return

ASP.NET Core Razor Page multiple path routing

别来无恙 提交于 2019-12-13 13:04:47
问题 I'm building a system using ASP.NET Core 2.0 Razor Pages (not MVC) and I'm having trouble adding multiple routes for pages. For example, all pages should be able to be reached by abc.com/language/ segment /shop/mypage or abc.com/language/shop/mypage, where both paths point to the same page. The segment path section is optional, then the pages do stuff with the optional segment info. The question mark syntax in the CombineTemplates markup doesn't seem to work, it seems to only work in the last

How to bind an List<IFormFile> property dynamically

谁说胖子不能爱 提交于 2019-12-13 10:21:18
问题 My issue is very similar to my previous post: How to bind a property to a dynamic list of objects However I am trying to do the same thing that solved this problem in my previous post with a more complex control, an input file selector. Due to this, my question is very similar, however in this case I am guessing the fix is slightly different since the previous solution did not work. Anyhow here goes: I am using the .net core 2.2 framework and am having trouble finding out how I can bind a

Input box as “date” on web when model is “int”

心不动则不痛 提交于 2019-12-13 09:09:19
问题 I am using ASP.NET Core v2 and Razorpages In SQL (and in the model) I have a field [FrDt] of data type "int" where I need to store a date value (as int) (I can't change the data type in SQL) If I set [DataType(DataType.Date)] in the model I automatially get an input "date" type on web. but when I submit, the values are not sent to the server. probably because the value is of type date and the field is int RAZORPAGE <input asp-for="@Model.AgrRow.FrDt" class="form-control" /> MODEL [DataType

Why does Razor Pages scaffolding use HTML Helpers (and not Tag Helpers) for Index, Details and Delete pages?

我怕爱的太早我们不能终老 提交于 2019-12-13 03:07:44
问题 I recently started my first project using Razor Pages, I am using EF Core and have scaffolded all of my models into CRUD Razor Pages. Something I noticed was that the Create and Edit Razor Pages that are generated use Tag Helpers to display the data. i.e. <div class="form-group"> <label asp-for="ViewModel.Name" class="control-label"></label> <input asp-for="ViewModel.Name" class="form-control" /> <span asp-validation-for="ViewModel.Name" class="text-danger"></span> </div> Whereas the Index,

Insert a modal razor page in the navbar. How to do it?

旧巷老猫 提交于 2019-12-13 03:04:34
问题 I'm building a new website and one of the requirements is to have the login form be a modal window. I'm trying to include it in the top navigation bar and it's only being rendered if the user is not logged in. How can I add this modal window with it's own model inside the top navbar? Are there any alternatives? If I delete the model and let an empty modal everything works perfectly but when I add it again it doesn't work, because the model of the page (in this case the index page) is a

Issue in System.Reflection.MethodBase.Invoke when debugging ASP.NET Core 3 in Visual Studio 2019

你离开我真会死。 提交于 2019-12-13 02:43:53
问题 I am writing an ASP.NET Core 3 Razor Page app in VS2019. I have started to get a message, "To prevent an unsafe abort when evaluating the function 'System.Reflection.MethodBase.Invoke' all threads were allowed to run..." Can someone tell what is going on and how to resolve it? Thanks 来源: https://stackoverflow.com/questions/58793111/issue-in-system-reflection-methodbase-invoke-when-debugging-asp-net-core-3-in-vi