1

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.!

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.