Asp net, how do I list items in real time?

Dan

I have the following view which displays the top 10 players ordered by their ranking.

@model IEnumerable<WebApplication3.Models.LiveRankingModel>

@{
    ViewData["Title"] = "LiveRanking";
}

<div style="text-align:center;">
    <h1><strong>Live Ranking</strong></h1>
</div>

<div style="display:flex; justify-content:space-around;">
    @foreach (var item in Model)
    {
    <div style="text-align: center; padding: 25px; border: 2px solid black; background-color: azure; border-radius: 25px; margin: 25px;">
        <div style="border:inherit;">
            <img src="data:image/jpg;base64,@System.Convert.ToBase64String(item.Image)" height="256" width="256" />
        </div>
        <hr />
        <h2>@item.Username</h2>
        <h3>@item.Score</h3>
    </div>
    }
</div>

Sorry for not listing my classes in an external .css file but, can I make it so that the clients don't have to reload the page to see the new results so I can also add a good looking transition effect when the players progress through the ranking?

Almeida

You've got two options

  1. You can use SignalR which is a MS library for ASP.NET project to add real-time functionality. the official website has a few good examples on how to use the library, like this one
  2. Or you can use Javascript setInterval + fetch (or jquery ajax)

    //this calls your api every 5 seconds
    //and retrieves your data to be rendered on the page
    setInterval(function(){
      fetch('api/your-endpoint')
    .then(function(response) {
      //your api should return an array of json object
      //here you iterate through the response object
      //create a new elemenet for each item
      //and append to an element already on the page
      //eg, create a an empty list on the page
      //and in here create li elements and append to it
    })
    .catch(function(err) {
      console.log(err);
    });
    }, 5000);
    

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

In ASP.NET Core 2.1 how do I add menu items after the user has logged in based on Role?

分類Dev

How do I (re-)enable real-time CSS editing in Visual Studio?

分類Dev

How do I handle real time search of a database in a Django web app?

分類Dev

How to only add items to a list that haven't been added before? (C# - ASP.NET)

分類Dev

How do I make a button event with innerhtml in ASP.NET

分類Dev

Get real time updates from a Facebook page I do not own

分類Dev

How do I check membership of items in a dict and list, within nested for loops?

分類Dev

How do I drop items in collections in rust

分類Dev

How to calculate date time values over python list items

分類Dev

How can I get a list of registered middleware in ASP.NET Core?

分類Dev

How can I list all of the configuration sources or properties in ASP.NET Core?

分類Dev

How do I call one item at a time stored in my list object?

分類Dev

How do I refresh the page in ASP.NET? (Let it reload itself by code)

分類Dev

How do I fix CS0433 errors in ASP.NET 5?

分類Dev

How do I inject ASP.NET 5 (vNext) user-secrets into my own utility class?

分類Dev

How do I make an XML file an embedded resource in a vNext (ASP.NET 5) class library?

分類Dev

How do I fix or get rid of ESLint definition requirement in ASP.NET Razor app?

分類Dev

ASP.NET Form - How do I send form data to external WCF Service

分類Dev

How do I pass array from Angular 6 to ASP.NET Core API for GET method?

分類Dev

How do I make project modifications to store Asp .net Core Angurlar 6 bundle in CDN

分類Dev

How do I connect to DB2 from a docker container using ASP.Net Core?

分類Dev

How do I get a property at index using custom validation in ASP.NET Core?

分類Dev

How to manage users in ASP.NET core with AD / LDAP? Do I store the users in a database?

分類Dev

How do I use string-ified enum in the body of a POST request to an ASP.NET core server?

分類Dev

How do I prevent ASP.NET MVC from binding query parameters?

分類Dev

How do I add an event handler for every request in ASP.NET that will be handled by PageHandlerFactory

分類Dev

How do I pass DateTime parameters from View to Controller in ASP.net MVC5?

分類Dev

How do I specify an asp.net mvc 5 resource file in a VB Class Data Annotation?

分類Dev

How do I properly use NUGET, for MVC (ASP.NET) projects?

Related 関連記事

  1. 1

    In ASP.NET Core 2.1 how do I add menu items after the user has logged in based on Role?

  2. 2

    How do I (re-)enable real-time CSS editing in Visual Studio?

  3. 3

    How do I handle real time search of a database in a Django web app?

  4. 4

    How to only add items to a list that haven't been added before? (C# - ASP.NET)

  5. 5

    How do I make a button event with innerhtml in ASP.NET

  6. 6

    Get real time updates from a Facebook page I do not own

  7. 7

    How do I check membership of items in a dict and list, within nested for loops?

  8. 8

    How do I drop items in collections in rust

  9. 9

    How to calculate date time values over python list items

  10. 10

    How can I get a list of registered middleware in ASP.NET Core?

  11. 11

    How can I list all of the configuration sources or properties in ASP.NET Core?

  12. 12

    How do I call one item at a time stored in my list object?

  13. 13

    How do I refresh the page in ASP.NET? (Let it reload itself by code)

  14. 14

    How do I fix CS0433 errors in ASP.NET 5?

  15. 15

    How do I inject ASP.NET 5 (vNext) user-secrets into my own utility class?

  16. 16

    How do I make an XML file an embedded resource in a vNext (ASP.NET 5) class library?

  17. 17

    How do I fix or get rid of ESLint definition requirement in ASP.NET Razor app?

  18. 18

    ASP.NET Form - How do I send form data to external WCF Service

  19. 19

    How do I pass array from Angular 6 to ASP.NET Core API for GET method?

  20. 20

    How do I make project modifications to store Asp .net Core Angurlar 6 bundle in CDN

  21. 21

    How do I connect to DB2 from a docker container using ASP.Net Core?

  22. 22

    How do I get a property at index using custom validation in ASP.NET Core?

  23. 23

    How to manage users in ASP.NET core with AD / LDAP? Do I store the users in a database?

  24. 24

    How do I use string-ified enum in the body of a POST request to an ASP.NET core server?

  25. 25

    How do I prevent ASP.NET MVC from binding query parameters?

  26. 26

    How do I add an event handler for every request in ASP.NET that will be handled by PageHandlerFactory

  27. 27

    How do I pass DateTime parameters from View to Controller in ASP.net MVC5?

  28. 28

    How do I specify an asp.net mvc 5 resource file in a VB Class Data Annotation?

  29. 29

    How do I properly use NUGET, for MVC (ASP.NET) projects?

ホットタグ

アーカイブ