I need to improve on my editLivros
, then I'll explain my project.
Autores
-------
IdAutor
Nome
Livros
--------
IdLivro
Nome
IdAutor
I am registering the Authors and Books correctly, when I register the Livro
, I make a ViewBag
for the list of authors:
LivrosController
to get Authors:
ViewBag.IdAutor = new SelectList(db.Autores, "IdAutor", "Nome");
% of% of Authors in DropDown
Books:
@Html.DropDownList("IdAutor", ViewBag.IdAutor as SelectList, new { @class = "form-control" })
Model Books
public partial class Livros
{
[Key]
public int IdLivro { get; set; }
[Required]
[StringLength(50)]
public string Nome { get; set; }
public int IdAutor { get; set; }
public virtual Autores Autores { get; set; }
}
Model authors
public partial class Autores
{
[Key]
public int IdAutor { get; set; }
[StringLength(50)]
public string Nome { get; set; }
}
Problem:
My problem is when I edit the book, automatically View Create
takes the Visual Studio
of the book and the Nome
of the book, however, I needed to generate IdAutor
with the authors, yes yes edit the author of the book, passing the IdAutor of the model dropbox
Thank you.