如我有    public class ValidationController : Controller
    {
        //
        // GET: /Validation/        public ActionResult Index(Models.User user)
        {
            return this.View(user);
        }
    }现在我想让他返回的View为我的指定的模板
如:
web.config有key <add key="TemplateName" = "Style/A/">
那么我的程序就会写为:    public class ValidationController : Controller
    {
        //
        // GET: /Validation/        public ActionResult Index(Models.User user)
        {
            return this.View(System.Configuration.ConfigurationManager.AppSettings["TemplateName"] + "Index", user);
        }
    }那么如何何写一个公共的类或怎么来改写他的View
来实现我在web.config里面定义了TemplateName


return this.View(user);
就相当于写
return this.View(System.Configuration.ConfigurationManager.AppSettings["TemplateName"] + "Index", user);

谢谢

解决方案 »

  1.   

    你只需要 定义一个配置的读取类 就可以了,读取指定节点 赋给该类的内部属性你就可以
    public ActionResult Index(Models.User user)
            {
                return this.View(Config.TemplateName, user);
            }
    这样来使用了
      

  2.   

    RE:
    我就是不想再写
    return this.View(Config.TemplateName, user);
    而是
    return this.View(user);
    还有你这里面还得加上Action名
    return this.View(Config.TemplateName+"Index", user);
    得这样,所以感觉麻烦谢谢