Home > Blockchain >  Set css multiple class runtime in tag in asp.netcore mvc page
Set css multiple class runtime in tag in asp.netcore mvc page

Time:09-07

I have a cshtml page where at page level i have a variable active having css class names. I want to set this variable in a button tag in the same page.

@{
    ViewData["Title"] = "Title";
    var active ="nav-link active";   
}   

<button class=@active id="nav-experience-tab" ... ...
    

But the output is:

<button  active="" id="nav-experience-tab" 

Second way:

var active ="class='nav-link active'";
<button @active id="nav-experience-tab" ... ... 

output is:

<button  active&#x27;="" id="nav-experience-tab"

Third way:

var active ="class=nav-link active";
<button @active id="nav-experience-tab" ... ... 
    

output is:

<button  active="" id="nav-experience-tab" 

Is there anyway to get the below?

<button  id="nav-experience-tab"

CodePudding user response:

You can set like this:

@{
    var active ="nav-link active";
}

<button  >click</button>

Demo

enter image description here

  • Related