Two actions for the same View

1

I have these two actions:

public ActionResult Lista(int PessoaId, string Nome, string Twitter) 
{
    Pessoa p = new Pessoa();
    p.PessoaId = PessoaId;
    p.Nome = Nome;
    p.Twitter = Twitter;

    return View(p);

}

public ActionResult Lista2(FormCollection form)
{
    Pessoa p = new Pessoa();
    p.PessoaId = Convert.ToInt32(form["PessoaId"]);
    p.Nome = form["Nome"]; ;
    p.Twitter = form["Twitter"]; ;

    return View(p);

}

I have this View:

@model Hello.Models.Pessoa
@{
    ViewBag.Title = "Lista";
}

<h2>Lista</h2>

<div>
    <b>PessoaId</b>
</div>
<div>
    @Model.PessoaId
</div>

<div>
    <b>Nome</b>
</div>
<div>
    @Model.Nome
</div>

<div>
    <b>Twitter</b>
</div>
<div>
    @Model.Twitter
</div>

Can not I add two actions to the same View? I tried adding the same View that I added in the first action in the second action, but it was not allowed.

    
asked by anonymous 21.03.2018 / 15:31

1 answer

3
  

Can not I add two actions to the same View?

Yes CAN , just specify the name of your View in the two Action , example

public ActionResult Lista(int PessoaId, string Nome, string Twitter) 
{
    Pessoa p = new Pessoa();
    p.PessoaId = PessoaId;
    p.Nome = Nome;
    p.Twitter = Twitter;

    return View("NomeDaView", p); 

}

public ActionResult Lista2(FormCollection form)
{
    Pessoa p = new Pessoa();
    p.PessoaId = Convert.ToInt32(form["PessoaId"]);
    p.Nome = form["Nome"]; ;
    p.Twitter = form["Twitter"]; ;

    return View("NomeDaView", p);

}

Where ViewName put the name of the file .cshtml , example Lista.cshtml , then, return View("Lista", p); .

21.03.2018 / 15:52