0

I am building a database of concerts that I have been to and the songs that were played. I have 2 class, a Show class and a Song class. The Show class has a List. I would like to know how to add songs to the show on the front end of the application. Right now I am using the default CRUD provided by Microsoft. It is in a basic format right now. I have added the class definitions below as well as the Create.cshtml for the Show class:

public class Show
{
    public int ID { get; set; }

    [Required]
    public String Venue { get; set; }

    [Required]
    public String City { get; set; }

    [Required]
    public String State { get; set; }

    [Required]
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime ShowDate { get; set; }

    public List<Song> TrackList { get; set; }
}

public class Song
{
    public int ID { get; set; }

    [Required]
    public int ShowID { get; set; }

    [Required]
    public String Title { get; set; }

    public TimeSpan Length { get; set; }
    public String Notes { get; set; }
}

Create.cshtml

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

<fieldset>
    <legend>Show</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.Venue)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Venue)
        @Html.ValidationMessageFor(model => model.Venue)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.City)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.City)
        @Html.ValidationMessageFor(model => model.City)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.State)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.State)
        @Html.ValidationMessageFor(model => model.State)
    </div>

    <div class="editor-label">
        @Html.Label("Date")
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ShowDate)
        @Html.ValidationMessageFor(model => model.ShowDate)
    </div>

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
4

0 回答 0