[英]Passing two or more parameters from model view to controller in EF Core / ASP.NET Core MVC application
[英]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.