在Create期间将对象添加到ICollection

时间:2015-03-22 17:41:48

标签: c# jquery visual-studio-2013 asp.net-mvc-5

我正在做一个简单的音乐收藏,我有以下课程吗?

public class Album {

    public int Id { get; set; }
    public string Title { get; set; }
    public string ImageName { get; set; }
    public AlbumType AlbumType { get; set; }
    public int ArtistId { get; set; }
    public virtual Artist Artist { get; set; }
    public virtual ICollection<Track> Tracks { get; set; }
}

public class Track {

    public int Id { get; set; }
    public string Title { get; set; }
    public int RunningTime { get; set; }
    public int AlbumId { get; set; }
    public virtual Album Album { get; set; }
}

当我创建专辑时,我想将x个曲目添加到albyum中。我想你可以用jQuery做,如果第一个被填充,你可以在其中为另一个轨道添加文本框。我还没有得到如何使用jQuery动态创建整个对象的线索 - 我只用一个文本框完成了prevoius,并将该值作为字符串添加。 我正在使用MVC5和Visual Studio 2013

编辑:

这是我的观点;

<h2>CreateAlbum</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Album</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.ImageName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.ImageName, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.ImageName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.AlbumType, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EnumDropDownListFor(model => model.AlbumType, htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.AlbumType, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.ArtistId, "ArtistId", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("ArtistId", null, htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.ArtistId, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>
}

我想以某种方式添加一个文本字段,指定要添加的曲目数,并创建一系列文本框,我可以模拟绑定到相册模型上的集合

0 个答案:

没有答案