Associate a controller with an existing view

0

Normally, when we create a Controller and associate a View with a Action , we right click on Action and Add View . Then it creates View , folder, and so on.

Now, when there is already a View , and I want to associate a Action with this View ? How do I do this? With the right there is no existing Add view option or something similar. How do I link?

    
asked by anonymous 13.03.2014 / 13:27

2 answers

2

Just change the return of your function, and put the name of view you want:

public ActionResult NomeFuncao()
{
    // código
    return PartialView("_NomeViewPartial");
}
    
13.03.2014 / 13:30
0

You can set the return of an Action to the desired View:

public ActionResult NomeAction(SeuModel seuModel)
{
    // Seu código aqui
    return View("SuaView", seuModel);
}

Furthermore, in your View you can also set what Action will be called in submit of your <form> :

@using (Html.BeginForm("NomeAction", "NomeDoController", FormMethod.Post))
{

}
    
13.03.2014 / 13:39