We help IT Professionals succeed at work.
Get Started

ASP.Net MVC C# Razor syntax

Arif Chowdhury
on
412 Views
Last Modified: 2016-02-27
Hello

I am new in MVC Razor and trying to convert a webform project to MVC. Now I am facing difficulties how to use dropdown which will be Razor C# syntax.

My Webfrom code -

aspx page - <asp:DropDownList runat="server" ID="ddl_1" AutoPostBack="true" >  </asp:DropDownList>
code behind -
if (ddl_1.Items.Count == 0)
            {
                ddl_1.DataSource = GetData(); //this function is working find and I am ok with this
                ddl_1.DataBind();

                ddl_1.Items.Insert(0, new ListItem("All", "0"));
                ddl_1.SelectedIndex = 0;                
            }

Please help me how it will be when I will use this in my MVC C# Razor project. I also want to show the selected value in a LABEL.

Thanks in advance
Comment
Watch Question
Developer
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 24 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE