Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8189253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:12:55+00:00 2026-06-07T03:12:55+00:00

I have my HTML / razor code that looks like this: @model Content.Grid <tr

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:12:57+00:00Added an answer on June 7, 2026 at 3:12 am

    I don’t see any reason why not. Give this a try:

    @model Content.Grid
    
    @{
        var result = string.Format("{0}.{1}", Model.RowKey.Substring(0, 2).TrimStart('0'), Model.RowKey.Substring(2, 2).TrimStart('0').PadLeft(1, '0'));
    }
    
    <tr id="row_@(Model.Row)" 
        data-pk="@(Model.PartitionKey)"
        data-rk="@(Model.RowKey)">
        <td>
            @result
        </td>
        <td>
            @result
        </td>
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have html code like this <tr class=odd> <td><b>Reason for Termination:</b></td> <td>this has bunch
I have HTML like this: <a href=# class=modalInput glow rel=#newsletter >Newsletter!</a> This opens a
I have the following razor code: <form id=logon action=/security/dev method=get> @Html.AntiForgeryToken() @Html.EditorFor(x => x.UserName)
I have a section of Razor code in one of my views that isn't
I'm trying the render an HTML list that looks like the following, using the
I have the following legacy code that I would like to mimic, with all
I have the following razor template html, although I can't figure out how to
Is it possible to render Razor in Html.Raw()? I have a dynamic page being
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>
I have html-file. I have to replace all text between this: [%anytext%]. As I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.