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

  • Home
  • SEARCH
  • 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 6841413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:57:48+00:00 2026-05-26T23:57:48+00:00

I am trying to display some rows in a table. Depending on the UserGroup,

  • 0

I am trying to display some rows in a table. Depending on the UserGroup, the View should show different markup. An administrator can delete rows, but a moderator can only mark them as visible or invisible.

How do i write a proper if else statement in Razor?

The page is displayed correctly, but the page title is Parse Error

This is my code:

@model MvcApplication3.Models.ViewModels.New.Question.MatrixRows

@{
    bool visible = Model.Visible;
}

<tr>
    <td>
    @if(visible) 
        {
        @Html.TextBoxFor(cn => Model.Row_Number, new { @class = "row required digits", size = 1 })
        }
    @if (!visible)
        {
        @Html.TextBoxFor(cn => Model.Row_Number, new { @class = "row required digits", size = 1, disabled = "disabled" })
        }
    </td>
    <td>
    @if(visible) 
        {
            @Html.TextBoxFor(bs => Model.Row_Description, new { @class = "rowdesc", size = 45 })
        }
    @if (!visible)
    {
        @Html.TextBoxFor(bs => Model.Row_Description, new { @class = "rowdesc", size = 45, disabled = "disabled" })
    }
    </td>
    <td>
        @if (HttpContext.Current.User.IsInRole("Administrator"))
        {
            @Html.HiddenFor(x => x.Delete, new { @class = "mark-for-delete" })
            @Html.LinkToRemoveNestedForm("Slet", "tr", "input.mark-for-delete")    
        }
        @if (HttpContext.Current.User.IsInRole("Moderator"))
        {
            @Html.HiddenFor(x => x.Visible, new { @class = "mark-for-visible" })
            @Html.LinkToDisableNestedForm("Deaktiver", "tr", "input.mark-for-visible")    
        }
        @Html.HiddenFor(id => Model.Row_Id)
    </td>
</tr>
  • 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-05-26T23:57:49+00:00Added an answer on May 26, 2026 at 11:57 pm

    The title has parse error because you did not set a title:

    @{
        ViewBag.Title = "Home Page";
    }
    

    now for an else statement, don’t use back the @ syntax:

    @if(visible) 
    {
        Html.TextBoxFor(bs => Model.Row_Description, new { @class = "rowdesc", size = 45 })
    }
    else
    {
        Html.TextBoxFor(bs => Model.Row_Description, new { @class = "rowdesc", size = 45, disabled = "disabled" })
    }
    

    You are checking for a boolean, you just need an else. Also for else if, it works the same.

    Your code could be simplified even more by just doing:

    @Html.TextBoxFor(bs => Model.Row_Description, new { @class = "rowdesc", size = 45, disabled = visible ? "" : "disabled" })
    

    Because you are displaying the same code anyways, just changing the attribute based on a value. To me, this becomes more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display a table to display of products (rows) in a
I'm trying to display all rows from one table and also SUM/AVG the results
I'm trying to display some large images with HTML img tags. At the moment
I am trying to display some message in span. but it is not working.
Right now, what i'm trying to do is display some lists on a page
I'm getting an 'System.OutOfMemoryException' when trying to generate some HTML reports. How can I
I'm trying to display an array of dictionaries variable in the table Cell Style
I'm having some trouble getting my Table and Colspans to work. I'm trying to
I'm trying to display a table full of twitter statuses (yes, this is the
I am trying to get a ListBox to display a concatenation of multiple rows

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.