ASP.NET MVC - Passing data between Views

Asked

Viewed 235 times

0

I have two tables: Tb_1 and Tb_2; both have a column id and are related to each other in a Microsoft SQL database.

For example: I selected the record paragraph 2 in Tb_1. When triggering the command Create, to Tb_2 receives the paragraph 2 in your field id

How do I click the button Create in Tb_1, send the same id selected in Tb_1 to the Tb_2 ?

  • Put these two classes in your question !!!

1 answer

1

I figured it out, if anyone wants a hint:

It was like this:

// GET: tb_visitas/Create
public ActionResult Create()
{
    ViewBag.id_broc = new SelectList(db.tb_brochuras, "id_broc", "descricao");
    ViewBag.id_g = new SelectList(db.tb_despertai, "id_g", "tema");
    ViewBag.id = new SelectList(db.tb_estrangeiros, "id", "nome");
    ViewBag.id_fol = new SelectList(db.tb_folhetos, "id_fol", "descricao");
    ViewBag.id_livros = new SelectList(db.tb_livros, "id_livros", "descricao");
    ViewBag.id_wp = new SelectList(db.tb_sentinela, "id_wp", "tema");
    return View();
}

So I switched to that:

// GET: tb_visitas/Create
public ActionResult Create(tb_estrangeiros estrangeiros)
{
    ViewBag.id_broc = new SelectList(db.tb_brochuras, "id_broc", "descricao");
    ViewBag.id_g = new SelectList(db.tb_despertai, "id_g", "tema");
    ViewBag.id = new SelectList(db.tb_estrangeiros, "id", "nome", estrangeiros.id);
    ViewBag.id_fol = new SelectList(db.tb_folhetos, "id_fol", "descricao");
    ViewBag.id_livros = new SelectList(db.tb_livros, "id_livros", "descricao");
    ViewBag.id_wp = new SelectList(db.tb_sentinela, "id_wp", "tema");
    return View();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.