I have my HTML / razor code that looks like this:
@model Content.Grid
<tr id="row_@(Model.Row)"
data-pk="@(Model.PartitionKey)"
data-rk="@(Model.RowKey)">
<td>
@(Model.RowKey.Substring(0, 2).TrimStart('0')).@(Model.RowKey.Substring(2, 2).TrimStart('0').PadLeft(1, '0'))
</td>
<td>
@(Model.RowKey.Substring(0, 2).TrimStart('0')).@(Model.RowKey.Substring(2, 2).TrimStart('0').PadLeft(1, '0'))
</td>
</tr>
This is just an example but in my application I have columns that repeat the same computation a few times. Is there a way that I could do this at the start of the
code and then just use the value in each column. Something like pre-computing this and then just placing the Obj local variable inside my ?
@{
Obj = Model.RowKey.Substring(0, 2).TrimStart('0'))
}
I tried this but can’t seem to get this to work.
Please note. I cannot change the Model in my application. The computation has to be inside the razor file.
I don’t see any reason why not. Give this a try: