Hi @sblb ,
As AgaveJoe said, you can use the JQuery DataTable's column configuration to change the data type from Int64
to string
.
Besides, you can also create a View Model and define the Size as a string
type, like this:
public class FilePathViewModel
{
//...
public string Size { get; set; }
}
Then, after query the SQL view and get the FilePath, you can use LINQ Query statement to convert the result from FilePath model to FilePathViewModel model, and change the Size value from Int64
to String
Type, like this:
[HttpGet("{id}")]
public IActionResult Get(int id)
{
//assume this is the sql view query result.
var filefromdatabase = new List<FilePath>()
{
new FilePath(){ Id=101, Name="A1", Path="P1", Type="T1", Size=87122},
new FilePath(){ Id=101, Name="A2", Path="P2", Type="T2", Size=122},
new FilePath(){ Id=101, Name="A3", Path="P3", Type="T3", Size=8712222}
};
//Then, use LINQ select statement to query the data and convert the mode from FilePath to FilePathViewModel.
var returndata = filefromdatabase.Select(c => new FilePathViewModel()
{
Id = c.Id,
Name = c.Name,
Type = c.Type,
Path = c.Path,
Size = c.Size < 1024 ? c.Size + "B" :
c.Size < 1024 * 1024? (c.Size / 1024) + "KB":
(c.Size / (1024* 1024)) + "MB"
}).ToList();
//Finally, return the converted data to the client and use the JQUery DataTable to display the result.
return Ok(returndata);
}
The result is like this:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion