簡體   English   中英

傳遞帶有兩個類的模型以使用EF5在asp.net中進行查看

[英]Passing a model with two classes to view in asp.net with EF5

我是ASP.NET和EF5的新手。 我正在使用EF5在VS2012,MVC4中進行項目。

我有一個類CreateClient那里是進一步兩類Clients, FullPackages象下面這樣:

public class CreateClient
{
    public Clients Clients { get; set; }
    public List<FullPackages> FullPackages { get; set; }
}

Clients是這樣的:

[Table("tblClients")]
public class Clients
{
    public int Id { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "Maximum {1} characters allowed for {0} field")]
    public string Username { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "Minimum {2} characters required for {0} field", MinimumLength = 5)]
    public string Password { get; set; }

    [Required]
    public string Name { get; set; }

    public string Email { get; set; }
    public string Country { get; set; }
    public string State { get; set; }
    public string City { get; set; }
    public string Street { get; set; }
    public string Contact { get; set; }

    [Required]
    public string Mobile { get; set; }

    public string Description { get; set; }
}

FullPackages類是:

public class FullPackages
{
    public int Id { get; set; }
    public int TypeId { get; set; }

    [Display(Name = "Package Type")]
    public string TypeName { get; set; } 
    public int AllowedSMS { get; set; }

    [Display(Name = "Time Span in Days")]
    public int? TimeSpan { get; set; }
    public decimal Price { get; set; }

    [Display(Name = "Package Name")]
    public string Name { get; set; }
}

我在我看來調用了這個模型

@model SmsServer.Models.CreateClient

並使用Clients類作為

@Html.LabelFor(model => model.Clients.Username)

但是我不知道要使用List<FullPackages>我想使用list的值。 我研究了該網站,但沒有找到任何有用的想法。因此,請幫助我...如何使用它

或者有什么方法可以更簡單地做到這一點:)

如果只想將它們列出來,則可以執行以下操作:

<table>
    <tr>
        <th>Id</th>
        <th>TypeName</th>
    </tr>
@foreach(var package in Model.FullPackages)
{
    <tr>
        <td>@package.Id</td>
        <td>@package.TypeName</td>
    </tr>
}
</table>

請注意,如果要回發它們,則必須使用索引循環而不是foreach。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM