Float
Float

Reputation: 39

Add or active a code html in asp.net mvc

I have this:

<div class="display"> display</div>
<div class="hidden" style="display:none">hidden</div>

How can I change the style from display:none to display:block in my code in asp.net mvc?

<div class="display"> display</div>
<div class="hidden">hidden</div>

Upvotes: 0

Views: 293

Answers (2)

AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

As I understand, you want to manipulate html codes by using c# like following;

<div class="hidden" @(isVisible ? "style='display:block'":"style='display:none'")>hidden</div>

isVisible is the c# variable. And you may write like following, too.

<div class="hidden" style="display:@(isVisible ? "block":"none")">hidden</div>

There are many different ways to do this. Read this document for more detail.

Upvotes: 0

CodingYoshi
CodingYoshi

Reputation: 27039

Give your element an id and then use pure JavaScript or JQuery to do it.

<!-- Give id first -->
<div id="some-id" class="hidden" style="display:none">hidden</div>

Pure JavaScript

document.getElementById('some-id').style.display = 'block';

JQuery

$('#some-id').css('display', 'block')

Upvotes: 1

Related Questions