Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Show and Hide Div using C# in MVC 3 Razor View Engine?

I have to write C# code for showing and hiding div in MVC3 for various controls based on switch case in C# .How can it be done without using JQuery Show or hide.. but in fully server side..?

like image 230
Vignesh Subramanian Avatar asked Mar 07 '13 04:03

Vignesh Subramanian


1 Answers

Add your switch statement directly into your .cshtml file. It will all be server-side at that point.

Controller:

public ActionResult Page()
{
    string data = "value1";
    return View(data);
}

CSHTML:

@model string; // this should be the Type your controller passes

<div>some html content</div>
@switch(Model) // Model is how you access your passed data
{
    case "value1":
        <div>...</div>
    break;
    case "value2":
        <div>...</div>
    break;
}
<div>more html content</div>
like image 144
Middas Avatar answered Oct 24 '22 04:10

Middas