[英]Storing and posting multiple rows of data ASP.Net MVC
我正在將項目從ASP.net表單轉換為ASP.Net MVC Core。
我正在創建一個新的收件人,該收件人可以有多種聯系方式。
在我的ASP.Net表單應用程序中,我有一個轉發器,我只是向轉發器添加了一個新元素,然后在提交表單時,我將遍歷轉發器的行並填充數據庫。
在MVC中如何做到這一點? 我是否只創建一個html表並遍歷這些行?
我是MVC的新手,所以不確定在這里如何進行。
供參考的是我的收件人數據模型及其聯系方式:
public class Recipient
{
[Key]
public Guid RecipientGUID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Company { get; set; }
public UserGroup Owner { get; set; }
public List<ContactMethod> ContactMethods { get; set; }
public User CreatedBy { get; set; }
public DateTime CreatedOn { get; set; }
public User LastModifiedBy { get; set; }
public DateTime LastModifiedOn { get; set; }
public bool IsActive { get; set; }
}
聯系方式:
public class ContactMethod
{
[Key]
[HiddenInput(DisplayValue = false)]
public Guid ContactMethodGUID { get; set; }
[Required(ErrorMessage = "Please specify a type.")]
public ContactMethodType Type { get; set; }
[Required]
public Recipient Recipient { get; set; }
public int CountryCode { get; set; }
[Required(ErrorMessage = "Please enter a identifier.")]
public string Identifier { get; set; }
public bool IsPreferred { get; set; }
}
您可以在.cshtml視圖文件中使用Razor語法。
<table>
@foreach var recipient in model.Recipients
{
<tr><td>@recipient.FirstName</td></tr>
}
</table>
查找ASP.NET MVC Razor教程
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.