DataTables Server Side

Joe

Member
Joined
Jun 22, 2022
Messages
5
Programming Experience
3-5
Hi, how would you achieve this using Datatables server side i.e. how would you add the 'Edit' link and display the correct date format?

I hope this make sense.

C#:
@foreach (var d in Model.Account)
                {
                    <tr>
                        <td>@d.UserID</td>

                        <td>
                            @d.AccountEmailAddress
                        </td>

                        @if (@d.DateAccountCreated != null)
                        {
                            <td>@d.DateAccountCreated.Value.ToString("dd/MM/yyyy hh:mm:ss tt")</td>
                        }
                        else
                        {
                            <td>@d.DateAccountCreated</td>
                        }

                        <td class="text-center">
                            @if (d.AccountApproved.HasValue && d.AccountApproved.Value == true)
                            {
                                <i class="fa fa-check" aria-hidden="true"></i>
                            }
                            else
                            {
                                <span class="text-color-red">
                                    <i class="fa fa-times" aria-hidden="true"></i>
                                </span>
                            }
                        </td>

                        <td class="text-center">
                            <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                            <a class="buttonstyle" href='~/2424?UserId=@d.UserID'>Edit</a>
                        </td>

                    </tr>
                }
 
Solution
This sounds like a product specific question. You may be better served by asking a forum geared towards that product.

To me, though, I would assume that API returns the data that you need along with the needed ids for each row, in your Razor you would then iterate over the returned rows and build up the UI and where appropriate, stick in the IDs like you are doing on line 34.

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
What is "DataTables server side"?

What problem are you currently encountering? Did you not know that all that Razor code above is actually compiled into C# code, then compiled dynamically, and then run on the server side?

Or is that Razor code used in some Blazor web assembly and you are trying to convert to Blazor server side?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,251
Location
Chesapeake, VA
Programming Experience
10+
This sounds like a product specific question. You may be better served by asking a forum geared towards that product.

To me, though, I would assume that API returns the data that you need along with the needed ids for each row, in your Razor you would then iterate over the returned rows and build up the UI and where appropriate, stick in the IDs like you are doing on line 34.
 
Solution
Top Bottom