razor-pages

How to return a PartialView from Core 2 RazorPage ViewModel Handler

爱⌒轻易说出口 提交于 2019-12-01 01:32:34
问题 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? 回答1: 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

There are no scaffolders supported for this item Visual Studio 2019

女生的网名这么多〃 提交于 2019-11-30 23:19:59
问题 I'm using Visual Studio 2019 version 16.0.4, and I tried to create a view or a partial one on asp.net core 2.1 (in views folder) but I get an error There are no scaffolders supported for this item Then I realized this problem happens when you have a folder which its name is "Pages" in your project that we use this folder for razor pages . If I remove the pages folder then the views scaffold works. When I put it back it is broken again. I don't know it is a bug or not but I need to use both

Why is Razor Pages the recommended approach to create a Web UI in Asp.net Core 2.0?

痞子三分冷 提交于 2019-11-30 06:21:50
问题 Learning new things needs an investment of time, space and energy. I am currently learning Asp.Net Core MVC 2.0. This ASP.NET Core tutorials overview states: Razor Pages is the recommended approach to create a Web UI with ASP.NET Core 2.0. This information confused me in deciding whether I have to stop learning Asp.net Core MVC and start learning Asp.net Core Razor Pages. Why is Razor Pages the recommended approach to create a Web UI in Asp.net Core 2.0? Any directions are welcome. 回答1: Razor

.Net Core 3.0 JsonSerializer populate existing object

寵の児 提交于 2019-11-28 22:52:45
问题 I'm preparing a migration from ASP.NET Core 2.2 to 3.0. As I don't use any more advanced JSON features (but maybe one as described below), and 3.0 now comes with a built-in namespace/classes for JSON, System.Text.Json , I decided to see if I could drop the previous default Newtonsoft.Json . Do note, I'm aware that System.Text.Json will not completely replace Newtonsoft.Json . I managed to do that everywhere, e.g. var obj = JsonSerializer.Parse<T>(jsonstring); var jsonstring = JsonSerializer

How to redirect on ASP.Net Core Razor Pages

孤者浪人 提交于 2019-11-28 13:27:29
I am using the new Razor Pages in ASP.Net core 2 Now I need to redirect I tried this, but the page does not redirect: public class IndexModel : PageModel { public void OnGet() { string url = "/.auth/login/aad?post_login_redirect_url=" + Request.Query["redirect_url"]; Redirect(url); } } How to redirect? You were very close. These methods need to return an IActionResult (or Task<IActionResult> for async methods) and then you need to return the redirect. public IActionResult OnGet() { string url = "/.auth/login/aad?post_login_redirect_url=" + Request.Query["redirect_url"]; return Redirect(url); }

Where are the Login and Register pages in an AspNet Core scaffolded app?

你离开我真会死。 提交于 2019-11-27 19:13:15
In VS 2017, I created a new ASP.NET Core Web Application. On the second page of the wizard, I chose Web Application, and for Authentication I chose "Individual User Accounts". Now, I'm trying to find the Pages associated with /Account/Register and /Account/Login . _Layout.cshtml brings in _LoginPartial.cshtml, much as it did in classic MVC: <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a asp-page="/Index">Home</a></li> <li><a asp-page="/About">About</a></li> <li><a asp-page="/Contact">Contact</a></li> </ul> <partial name="_LoginPartial" /> </div> If the user is not

How to redirect on ASP.Net Core Razor Pages

扶醉桌前 提交于 2019-11-27 07:36:39
问题 I am using the new Razor Pages in ASP.Net core 2 Now I need to redirect I tried this, but the page does not redirect: public class IndexModel : PageModel { public void OnGet() { string url = "/.auth/login/aad?post_login_redirect_url=" + Request.Query["redirect_url"]; Redirect(url); } } How to redirect? 回答1: You were very close. These methods need to return an IActionResult (or Task<IActionResult> for async methods) and then you need to return the redirect. public IActionResult OnGet() {

Example AJAX call back to an ASP.NET Core Razor Page

心已入冬 提交于 2019-11-26 17:53:42
I've found examples of have multiple handlers on a page and the associated naming convention (ie OnPostXXX) and 'asp-post-hanlder' tag helper. But how can I call one of these methods from an AJAX call. I have an older example with a typical MVC view and controller but how does this work with a Razor Page? For example if I take the base application and modify the About.cshtml page to the following: @page @model AboutModel @{ ViewData["Title"] = "About"; } <h2>@ViewData["Title"]</h2> <h3>@Model.Message</h3> <input type="button" value="Ajax test" class="btn btn-default" onclick="ajaxTest();" />

Where are the Login and Register pages in an AspNet Core scaffolded app?

妖精的绣舞 提交于 2019-11-26 12:09:47
问题 In VS 2017, I created a new ASP.NET Core Web Application. On the second page of the wizard, I chose Web Application, and for Authentication I chose \"Individual User Accounts\". Now, I\'m trying to find the Pages associated with /Account/Register and /Account/Login . _Layout.cshtml brings in _LoginPartial.cshtml, much as it did in classic MVC: <div class=\"navbar-collapse collapse\"> <ul class=\"nav navbar-nav\"> <li><a asp-page=\"/Index\">Home</a></li> <li><a asp-page=\"/About\">About</a><

Example AJAX call back to an ASP.NET Core Razor Page

时光毁灭记忆、已成空白 提交于 2019-11-26 04:26:55
问题 I\'ve found examples of have multiple handlers on a page and the associated naming convention (ie OnPostXXX) and \'asp-post-hanlder\' tag helper. But how can I call one of these methods from an AJAX call. I have an older example with a typical MVC view and controller but how does this work with a Razor Page? For example if I take the base application and modify the About.cshtml page to the following: @page @model AboutModel @{ ViewData[\"Title\"] = \"About\"; } <h2>@ViewData[\"Title\"]</h2>