Preface:
I have a static formatting function in my backend, which takes an int Id and returns string SerialNumber. I want to keep it in on place.
In one of the Views – I am showing a column of Serial Number. This column is sortable (by sql query), so the content of the column should be Id value, so I am modifying the displayed value with js to convert Id to Serial.
So, I got this script in my .cshtml View:
<script>
function formatToSerial(id) {
return @MyFormater.GetFormatedSerial(int.Parse(id));
}
</script>
Problem: argument “id” is not recognized in this context.
Question: is there a nice built-in way to pass the js function argument to inline c# call? Or should I stick with duplication string formatting function separately for js?
What I did tried so far: I was looking into making the formatting JSInvokable and use it that way. But If I understood correctly – this is Blazor functionality, which I am not using in this project.
3