Questions tagged [razor-pages]

1

votes
3

answer
43

Views

How to properly use Model Binding to get Radio Button value in Razor Pages

I have a set of radio buttons on a razor page, and I want to get and use the selected value of these radio buttons in my server-side code once the form has been submitted. HTML for radio buttons: 1 2 3 4 I am using model binding to get the value on the server-side: public class BoostNo { [Required(E...
bbbb
1

votes
0

answer
15

Views

Razor Pages .NET Core 2.1 Child Routes

I'm working on a .NET Core 2.1 Razor Pages application, and can't figure out why the router isn't matching my expectations. In my application an Orchestration object has a collection of Rules objects. An Orchestration is defined queried at the DB with a Guid. My Index.cshtml in the Orchestration f...
wootscootinboogie
0

votes
1

answer
31

Views

Form in Layout: Razor Pages

I have a select in a form in the Layout of my web app that needs to be accessible from every page. The form sets a session variable that is required to load data on every page. Select Customer Vandalay Kramerica I know I can make a base PageModel and inherit from that on every page in order to resp...
Steven B.
0

votes
0

answer
4

Views

Redirect to Page with ID in Razor Pages

I'm trying to get my app to redirect to the previous page after it updates the database but I can't seem to figure it out. What's complicating it is that the previous page isn't just a simple page. It's populated with information pulled but a specific row in the database so the URL has blah blah bl...
athomas
1

votes
4

answer
2.5k

Views

How to add jQuery UI to Asp.Net Core VS2017?

I have installed jQuery UI using Bower in VS2017. When I look in Solution Explorer I can see that the Bower package seem to have been installed but I can't find them in the wwwroot folder so I don't know how to add them to the _layout.cshtml file. What is the procedure for adding jQuery UI to my AS...
Thomas Adrian
1

votes
1

answer
76

Views

Disable get request on logout razor page

I have a razor page (asp.net core 2.1) for logout (/identity/account/logout) which shows its view on get request and perform logout on post request. I want to remove the view and leave only the logic for logout which is the post request. I deleted OnGetAsync() method from the PageModel, but the view...
Iliyan Ivanov
1

votes
1

answer
372

Views

How do you create a confirmation message in .net Core 2.1 RazorPages?

Hopefully not a dumb question- I am rewriting an app from .net core mvc to .net core Razor. In MVC I use viewbags to create and display confirmation of actions being successful or display error message if not. Viewbags don't seem to be used or available in the same way for Razor pages in .net core 2...
Lyndon Sundmark
1

votes
1

answer
147

Views

Calling Action in Razor Pages

as a newbie to Razor Pages I have a question regarding calling methods from Razor Page. I have a method called subtractProduct defined in my domain model. In my Index Page code I define IActionResult sellProduct which calls subtractProduct on specified ProductId. But I have no clue how to call thi...
xcelm
1

votes
2

answer
43

Views

In ASP.NET Razor, how to include model attribute in a string?

Is there a clean way to include a string substitution inside a razor page? That is, I have some razor code that looks like this but does not work. I feel like I'm missing some punctuation.
Pete
0

votes
0

answer
13

Views

Using Html in a SQL table and retrieving it in a foreach statement C#

I am having some issues with Html stored in a Sql table. I am using font Awesome and storing the "i" tags in a table record so that each record may or may not have different set of tags depending on the case. The problem is Html.DisplayFor does not "Display" it correctly. In other words it looks lik...
S.Purtan
0

votes
0

answer
4

Views

Insert Jquery variable in Razor View

I'm stuck on a issue where I need to insert a jquery variable in a Razor View. For instance I have the following code: $(document).ready(function () { var options = { pages: @Html.Raw(Json.Encode(ViewBag.Array)) , singlePageMode: true }; $("#pdfbox").flipBook(options); }) which gives an output: $(d...
Reynold Dmello
0

votes
1

answer
6

Views

Url.Action alternate in razor page view model class

What can be used to get the URL of the page which is in this path of the project /Pages/Account/Logout.cshtml This is using view model razor pages and not mvc controller/action When I use Url.Action("/Account/Logout", new { logoutId = ogoutId }); it says cannot resolve action /Account/Logout
Umair
2

votes
1

answer
171

Views

ViewData is not passed to layout in ASP.NET Core 2.1

Edited I have an ASP.NET Core 2.1 website which I've scaffolded all of its Identity items. The scaffolding process created a layout file in this location: /Areas/Identity/Pages/Account/Manage/_Layout.cshtml As I wanted to use the layout globally, I have moved the layout file (with cut-paste) to this...
0xaryan
1

votes
2

answer
43

Views

ASP.NET Razor Pages - Conditional redirection

In one of my EF entities, I have a boolean field that indicates whether there is or not a maintainance going. Thus, I would like to reroute all my pages to a 503 error page only if this boolean is set to true. I could put the following piece of code in every Page: if (_context.SystemParameters.First...
Lovy
1

votes
1

answer
27

Views

Custom classes in ASP.Net Core

New to .NET Core I'm trying to make a custom class, that I can call from different controllers. In the root of my project I've created a folder called Helpers. In that I've created EncryptString.cs: namespace VPV.Helpers { public class EncryptString { public string Index(string val, string salt) { b...
Mads
2

votes
2

answer
47

Views

how can i display a list of roles in Razor Pages view?

I am trying to add a list of the roles in my asp.net core web application to a Razor Page but I'm not sure how to do this. I want the user to be able to choose what role a new user being registered is to be. The input model itself looks like this: public class InputModel { [Required] [DataType(DataT...
dstewart101
0

votes
0

answer
3

Views

Resetting search criteria in a razor page with another button that is not the submit button of the form

I have a razor page that I developed based off of this Add Search tutorial by Microsoft. Inside of the form on the page I have a Filter button which calls the OnGetAsync() method query string params and is working great. However, I added a reset button to the form as well. The reset button clears th...
Blake Rivell
1

votes
2

answer
558

Views

Override razor views in asp.net core razor pages

In asp.net core mvc, I had multiple locations specified for the views. so, if view was missing in one location, it gets fetched from the other location. I have a CMS with asp.net core mvc where controllers and views comes in a compiled library. If I don't want to use the view from the library, it's...
eadam
3

votes
1

answer
64

Views

Localized page names with ASP.NET Core 2.1

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.A...
LGSon
2

votes
1

answer
38

Views

AJAX Request to Method Contained in Class File

I'm trying to make an AJAX request on a Razor Page, calling a method contained in separate class file (NOT in the pagemodel for the page - as I eventually want to make the same request from multiple different pages). Unfortunately, the request fails. I think it may have to do with the syntax I've us...
bbbb
6

votes
1

answer
949

Views

Razor Pages and Razor Views

Is it a good idea to mix Razor Pages with Razor Views in the same ASP.NET Core 2.0 app? If I understand it correctly, the benefit of using Razor Pages is that they don't need controller actions. In my app, I have some pages that simply return a React app. I feel Razor Pages are perfect for this beca...
Sam
2

votes
1

answer
127

Views

Render a Partial View in _layout.cshtml using the partialview model instance with DBContext dependency injection

At first I'd like to say I'm new to Asp.net Core and also with concepts of dependency injection (DI). I'm reading a lot trying understand it, so I ask for patience. I'm trying Razor Pages (not MVC) and my goal is to render to "_layout.cshtml" a partial view, in which information obtained using the...
Marcoscdoni
20

votes
2

answer
5.3k

Views

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

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 _LoginPart...
5

votes
1

answer
455

Views

Routing to an ApiController in a razor page app?

I created a ASP.NET Core Razor page app (asp.net version 2.1.1). It works just fine with the normal Pages but I also want an ApiController as in this tutorial: https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc?view=aspnetcore-2.1 However, when I create my controller just as in the e...
Ms01
0

votes
0

answer
22

Views

razor named handler and BindProperty

I am trying to send an ajax post request to a razor page. This razor page has some public properties with [BindProperty]. For the ajax request I am trying to use a named handler. @page "{title}" [BindProperty] public BookViewModel BookModel { get; set; } public IActionResult OnPostMarkdownInput(stri...
Doidel
1

votes
1

answer
742

Views

asp.net core pass data from content page to layout

I'm trying to set a master layout.cshtml page that works consistently for all page except for one or two (typically login and logout). In my layout I'd like to display some elements that I want to not display for these special pages. I've seen partial views and sections and they all seem to work "b...
gbjbaanb
2

votes
0

answer
856

Views

Return another page from Razor Page

In MVC we used to have return View("foo",modeldata), so I could return any arbitrary view with its associated model. How do I do something like that in Razor Pages? I'm looking for something like var p=new ListingPageModel(); // populate p model return p.Page(); I have tried this, to no avail: Http...
faibistes
3

votes
2

answer
2k

Views

How to redirect on ASP.Net Core Razor Pages

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 redire...
Tony
4

votes
1

answer
893

Views

ASP.Net Core Razor Pages dynamic list

I want to create a website with Razor pages to maintain spaces and the according rooms. So, in my model a space has a list of rooms. public class Space { public int Id { get; set; } public string SpaceName { get; set; } public List Rooms { get; set; } public Space() { this.Rooms = new List(); } } In...
El Stefano
4

votes
1

answer
153

Views

What is the difference between partial tag helper and HTML helper in asp.net core?

What is the difference between partial tag helper implemented in .net core 2.1: and @await Html.PartialAsync("_AuthorPartial") Which one should I use in the production and what are the benefits?
GoldenAge
1

votes
2

answer
48

Views

Razor Pages: Confused about all the return types and when to use them

I'm generally confused about the "why" (not the "how") of using certain C# return types in Razor Pages. In some instances, I understand the "why", but am not clear on when I should use one over the other. My initial confusion began with the Asynchronous types, but I understand that now. It was also...
REMESQ
1

votes
1

answer
219

Views

.net core routing to a razor pages area based on current domain name?

I'm currently trying to architect a application to host multiple websites from a single .net core application. Ideally, I would like to show completely different Razor pages based on the domain name the application is being accessed from. Ideally, I would like to have my razor pages broken down into...
IMelancon
2

votes
1

answer
526

Views

What does Page() method in Razor Pages OnPost method do?

ASP NET CORE 2 I have following page model code public class CreateModel : PageModel { private readonly IItemService _itemService; public ItemCreateViewModel ItemModel { get; set; } public CreateModel(IItemService itemService) { _itemService = itemService; } // all related data downloaded from db, s...
Grumpy Android
2

votes
1

answer
146

Views

When to use LocalRedirect vs RedirectToPage

With ASP.Net Core 2.1 Razor Pages, what is the best practice on using LocalRedirect vs RedirectToPage? It seems they can be used interchangeably when redirecting to a page within the current website. Is there an advantage to one over the other?
Godminders
2

votes
1

answer
52

Views

Razor Pages - Trying to Implement Action Filter on Razor Page

I want to write a custom filter which will check whether a user is logged in to my site, and redirect them back to the login page if they aren't. I want the filter to apply automatically to the page when it loads. I have tried the solution shown below, but the filter doesn't work at the moment. Filt...
bbbb
25

votes
1

answer
8.6k

Views

ASP.NET Core 2.0 Razor pages vs Full MVC Core

There has been a question at SO Why is Razor Pages the recommended approach to create a Web UI in Asp.net Core 2.0? where Steve Smith has kindly explained the benefits of using Razor Pages over full MVC from the perspective of having less files. I've been using Razor Pages for a while and noticed t...
Ivan Zaruba
3

votes
1

answer
2k

Views

How to return a PartialView from Core 2 RazorPage ViewModel Handler

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
32

votes
3

answer
4.4k

Views

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

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 s...
Artificial Stupidity
2

votes
1

answer
701

Views

Accessing Async Property in Razor page

I am trying to bring up a simple .NET Core 2.0 Web Application with Razor pages. The page is connected to an equally simple Core 2.0 Web API. I have a simple class: public class About : PageModel { private ServiceProxy serviceProxy; public About(ServiceProxy serviceProxy) { this.serviceProxy = serv...
Donald Airey
2

votes
1

answer
94

Views

Async timing issue

I am making a call to a repository which wraps EF core, messing about with the contoso example public async void PopulateFacultySL( object selectedFaculty ) { var data = await GetUnitOfWork().Faculties.GetAllAsync(); FacultySL = new SelectList( data, "Id", "Name", selectedFaculty ); } When refreshin...
Simon

View additional questions