开发者

MVC3 Details Action Foreign Key Name Field

开发者 https://www.devze.com 2023-02-16 03:13 出处:网络
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.

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 questio开发者_JAVA百科n 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消