0

My ModelClass in

Public class Employee
{
    public SelectList PublishMonth { get; set; }
}

On view, it display as dropdown and working fine. Now on another partial view, i need to display all employee. I get List and i need to display value of PublishMonth for each employee. if i display like <%=item.PublishMonth.SelectedValue%> it display ID instead of text. How can i get text?

1
  • My assingment is like oEmp.PublishMonth = new SelectList(pm, "PMid", "pmname", oAllEmployee[i].PMid); and view it is <%=Html.DropDownList("ddlmonth", Model.Employee[0].PublishMonth, new{ @class = "dropdownlist" } ) %>&nbsp;&nbsp; Commented Aug 24, 2011 at 14:59

1 Answer 1

1

I would do something like this:

public class Employe
{
  SelectList PublishedMonths {get;set;}
  int Month {get;set;}
}

in the view:

<%= Html.DropDownListFor(x => x.Month, PublishedMonths) %>

Then when you post the form, the selected value will be binded in the Month property.

When you build your SelectList, I supposed you have something that sets the DisplayValue of the item.

I will suppose it is an extension method on an int

In the view I would do:

<%= Model.Month.GetDisplayValue() %>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.