如何在Asp.net core中将列表从视图发布到映射到viewModel的控制器?
这是我的视图模型如何在Asp.net core中将列表从视图发布到映射到viewModel的控制器?,asp.net,asp.net-core,controller,viewmodel,Asp.net,Asp.net Core,Controller,Viewmodel,这是我的视图模型 public class VideoViewModel { public string Movie { get; set; } public int Order { get; set; } public IList<VideoContent> VideoContents { get; set; } } 公共类VideoViewModel { 公共字符串电影{get;set;} 公共整数顺序{get;set;} 公共IList视频内容{ge
public class VideoViewModel
{
public string Movie { get; set; }
public int Order { get; set; }
public IList<VideoContent> VideoContents { get; set; }
}
公共类VideoViewModel
{
公共字符串电影{get;set;}
公共整数顺序{get;set;}
公共IList视频内容{get;set;}
}
如何将数据从视图中的字段传递到映射到viewModel中我的集合的控制器
在我看来,这段代码正在将电影和订单传递给控制器,但我不知道如何发送收藏
@model ViewModels.VideoViewModel
<form method="post">
<div class="form-group">
<label for="movie">Movie</label>
<input type="text" name="Movie" id="movie" class="form-control">
</div>
<div class="form-group">
<label for="order">Order</label>
<input type="text" name="Order" id="order" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Add to database</button>
</form>
@model ViewModels.VideoViewModel
电影
命令
添加到数据库
提前谢谢
/KalleASP.NETCore使用name属性将输入字段中的数据绑定到视图模型 这应该适用于传递集合
for(int c = 0; c < VideoContents.Count; c++)
{
<input name="VideoContents[@c].FirstProperty" value="@Model.VideoContents[@c].FirstProperty"/>
<input name="VideoContents[@c].SecondProperty" value="@Model.VideoContents[c].SecondProperty"/>
}
for(int c=0;c
非常感谢您!你救了我一天:-)