Home > Net >  Configure Routing on RazorPages
Configure Routing on RazorPages

Time:11-18

Configure routing to enable getting images by not only the standard path by images/{image_id}

For images pages how can I configure routing like that?


    @page
    @model GetandTake.Pages.Categories.ImagesModel
    <h3>All Images</h3>
    @foreach (var category in Model.Categories)
    {
        @if (@category.ImagePath != null)
        {
            string imagePath = $"https://localhost:7005/"   @category.ImagePath;
            <img src="@imagePath"  width="250px;" />
        }
    }

CodePudding user response:

Here is a working demo about showing images in wwwroot:

Configuration:
...
  app.UseHttpsRedirection();

    app.UseStaticFiles();

    app.UseRouting();
...

wwwroot:

enter image description here

view:

@foreach (var category in Model.Categories)
    {
        @if (@category.ImagePath != null)
        {
            <img src="/@category.ImagePath"  width="250px;" />
           //category.ImagePath is 1.PNG here
        }
    }
  • Related