Kal*_*son 2 asp.net controller viewmodel asp.net-core
这是我的 ViewModel
public class VideoViewModel
{
public string Movie { get; set; }
public int Order { get; set; }
public IList<VideoContent> VideoContents { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如何将数据从视图中的字段传递到映射到我的视图模型中的集合的控制器?
在我看来,这段代码正在将 Movie 和 Order 传递给控制器,但我不知道如何发送集合。
@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>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
/ 卡勒
ASP .NET Core 使用 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"/>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1976 次 |
| 最近记录: |