栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

ASP.NET MVC中切换模板页(不同目录的cshtml文件)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ASP.NET MVC中切换模板页(不同目录的cshtml文件)

看来以后建立一个父类控制器还是有必要的。。。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NETMVC切换模板.Controllers
{
public class baseController : Controller
{
protected override void onResultExecuting(ResultExecutingContext filterContext)
{
ViewResult viewResult = filterContext.Result as ViewResult;
if (viewResult != null)
{
string x = Request.QueryString["x"];
string text = string.IsNullOrEmpty(x) ? "" : "/Templete/Blue";
string arg = string.IsNullOrEmpty(text) ? "" : text;
string arg2 = filterContext.RequestContext.RouteData.Values["Controller"].ToString();
string arg3 = filterContext.RequestContext.RouteData.Values["Action"].ToString();
if (string.IsNullOrWhiteSpace(viewResult.ViewName))
{
viewResult.ViewName = string.Format("{0}/Views/{1}/{2}.cshtml", arg, arg2, arg3);
return;
}
}
base.onResultExecuting(filterContext);
}
}
}

源码下载:
http://ohpxbzczu.bkt.clouddn.com/ChangeMuBan.zip

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/231720.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号