Adding items to the model list inside the model

I have a model like this:

public class RecipientModel
{
    public int RecipientID { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email Address")]
    public string EmailAddress { get; set; }

    [Required]
    [Display(Name = "First Name")]
    public string FirstName { get; set; }

    [Required]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }

    [Display(Name = "Active?")]
    public bool Status { get; set; }

    [Required]
    [Display(Name = "Notifications")]
    public RecipientNotificationModel[] RecipientNotifications { get; set; }
}

public class RecipientNotificationModel
{
    [Required]
    [Display(Name = "Notification Type")]
    public int NotificationTypeID { get; set; }

    [Display(Name = "Notification Group")]
    public int NotificationGroupID { get; set; }

    [Required]
    [Display(Name = "Notification Category")]
    public int NotificationCategoryID { get; set; }
}

And what I plan to do is something like this:

MVC Razor - List of

The idea is that I want to add elements to RecipientModel.RecipientNotifications, but I have several problems for such a task.

Problem 1 - Form Validation Submission

My first problem is that it checks the form when I click the button Add Notification. It should only be checked at the touch of a button Add Recipient. The view looks something like this:

@using (Html.BeginForm()) {
    // .... recipient fields
    // Add Notification button
    // .... notification list
    // Add Recipient button
}

I thought about changing the button Add Notificationto a non-submit button and using js on it, which will show a hidden modal html popup like this:

<div id="addNotification" style="display:none">
    @using (Html.BeginForm()) {
        // ... notification fields
    }
</div>

but now, how can I get the value of this form and add it to the current property RecipientNotifications?

Problem 2 - Delete Notification

, Html.ActionLink submit, , , , .

. .

+4
1

1) AngularJs ajax. 2) angular . 3) ng-repeat, .

0

All Articles