开发者

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,..开发者_StackOverflowetc... 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.!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜