3
I need to upgrade my editLivros, Next I’ll explain my project.
Autores
-------
IdAutor
Nome
Livros
--------
IdLivro
Nome
IdAutor
I am registering the Authors and Books correctly, when I am registering the Livro, I make a ViewBag for the list of authors :
LivrosController to catch the Authors:
ViewBag.IdAutor = new SelectList(db.Autores, "IdAutor", "Nome");
DropDown of the Authors in View Create 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 the Visual Studio picks up the Nome of the book and the IdAutor of the book, however, needed to generate a dropbox with the authors, yes edit the author of the book, passing the model Idautor Autores
Thank you.
That is, do you want to be able to save several authors for a book? Post how are the Models Authors and Books.
– Randrade
@Randrade actually friend, I wanted to leave a dropdown with the authors in the Edit view, then I choose the author by name and he picks up the Idautor, thank you for answering
– Furlan
The same thing of this answer?
– Randrade
@Randrade put in the question the Model of Authors and Books
– Furlan
actually no, because he doesn’t get Idautor @Randrade
– Furlan
Not only submit a Selectlist again in Viewbag and create the Dropdownlist?
– Jedaias Rodrigues
Orra, I got @Jedaiasrodrigues , was under the nose kkk, tell me one thing, and to leave the author who is default in the dropdown?
– Furlan
I’ll edit a reply!
– Jedaias Rodrigues
Ok @Jedaiasrodrigues thanks in advance
– Furlan