dexter
dexter

Reputation: 1207

asp.net MVC return View - add variable in viewpath

i have different different pages which i want to call from one controller action

here is what i've done

  public class TemplatesController : Controller
{
    public ActionResult Select(int id)
    {

        return View("Temp"+(id));


    }

}

i have different view pages like Temp1, Temp2, Temp3,..etc... the id is fetched properly but i think there is a problem in concatenation

i want final result to be

return view("Temp1");

in another case it would be

return view("Temp2");

so that these pages can be called without creating controllers for each of the pages.

pls help.!

Upvotes: 1

Views: 614

Answers (1)

LiamB
LiamB

Reputation: 18586

return View("Temp"+id.ToString());

The parameter is a String, so you can build the string up however you want.

string RetView = "Temp"+id.ToString();
return View(RetView);

so that these pages can be called without creating controllers for each of the pages.

Although i'm not sure if this is good practice, I suppose it depends on how many views you have.

Upvotes: 2

Related Questions