0

Based on great info out here...I've got my edit and create VM working great. My VM contains "SelectList" collections and the DD look like this.

@Html.DropDownListFor(model => model.softwaremanufacturerid, Model.ListOfManufacturers)

My question has to do with the Details action. Is there a way I can use the list I've already built (the lists are in an ancestor VM class that all the concrete ones inherit) to display the Manufacturers name instead of the FK? What I get now is just the FK.

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bayrat
  • 161
  • 1
  • 3
  • 17

2 Answers2

1

The list values are never POSTed. Only the selected value. So in the corresponding action to which you are submitting this form you could use this value to fetch back the list from the database if you ever needed to redisplay the same view.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I don't think I was clear. I'm talking about the Details action, so they've selected an item from a list (index) item and now the details view is presented. I was hoping to take a FK value and display it's name vs. the FK. I already have my "SelectList" collection in my view...I was hoping to us an HTML helper to grab the display name based on the FK from this list. – Bayrat Mar 14 '11 at 11:54
0

You might be able to do something like this:

@Html.DisplayFor(model => model.SoftwareManufacturer.Name)

This assumes that you have classes which look like this:

public class Product
{
    [Key]
    public Guid Id { get; set; }
    public String Name { get; set; }
    [ForeignKey("SoftwareManufacturer")]
    public Guid SoftwareManufacturerId { get; set; }
    public virtual Manufacturer SoftwareManufacturer { get; set; }
}

public class Manufacturer
{
    [Key]
    public Guid Id { get; set; }
    public String Name { get; set; }
}

I think that will do what you want.

Drgnkght
  • 121
  • 4