I have a question that still persists after doing some searches.
It is as follows, assuming I have a form, where I register multiple emails for a single user, how do I record these multiple emails in their table? Here are the examples: (if you have any errors please feel free to correct)
Models and ViewModel:
public class Email
{
public int EmailID { get; set; }
public int UsuarioID { get; set; }
public string Email { get; set; }
[ForeignKey("UsuarioID")]
public virtual Usuario Usuarios { get; set; }
}
public class Usuario
{
public int UsuarioID { get; set; }
public string Nome { get; set; }
public virtual ICollection<Email> Emails { get; set; }
}
public class UsuarioNovo
{
[Required]
public int Nome { get; set; }
[Display(Name = "E-mail")]
public string Email { get; set; }
}
In html, I created a div with the class .dc-box-clonar
with the inputs and a script in js to clone the div when clicking on a certain link, it follows the script:
$('.dc-box-clonar').hide();
$('.control-add-box').on('click', function (e) {
e.preventDefault();
var newElem = $(this).parent().find('.dc-box-clonar:first').clone();
newElem.find('input').val('');
newElem.prependTo($(this).parent()).show();
var height = $(this).prev('.dc-box-clonar').outerHeight(true);
$("html, body").stop().animate({ scrollTop: $(this).offset().top - 520 }, 600);
});
What would the Controller look like with EF instructions? And this way of cloning in js right on this occasion?