我对MVC和Razor的了解很基本,所以我希望它的内容相当简单。基本上,我有我的Controllers
正常,但我的Views
文件夹具有嵌套结构。例如,而不是:如何让MVC在嵌套文件夹中查找视图
Views -> Index.cshtml
它就像
Views -> BrandName -> Index.cshtml
我创建了一个自定义的帮手解决这个问题,但我不知道它如何与查询字符串的URL工作的?此处作为一例是控制器:
private DataService ds = new DataService();
//
// GET: /Collections/
public ActionResult Index()
{
return View();
}
//
// GET: /Collections/Collection?id=1
public ActionResult Collection(int id)
{
var collectionModel = ds.GetCollection(id);
return View(collectionModel);
}
但是我如何才能ActionResult Collection
查看:
Views -> Brand2 -> Collection.cshtml
这里的变通办法,我使用:
public static string ResolvePath(string pageName)
{
string path = String.Empty;
//AppSetting Key=Brand
string brand = ConfigurationManager.AppSettings["Brand"];
if (String.IsNullOrWhiteSpace(brand))
path = "~/Views/Shared/Error.cshtml"; //Key [Brand] was not specified
else
path = String.Format("~/Views/{0}/{1}", brand, pageName);
return path;
}
不明确。你有一个解决方法(主要是工作),但发布一个非常简单的控制器呢? – 2012-03-06 11:09:54
@HenkHolterman我没有看到太多的观点与解决方法进行,因为有可能自然而然地做到这一点 – ediblecode 2012-03-06 11:11:01
@HenkHolterman不知道问题不清楚怎么回事 – ediblecode 2012-03-06 11:12:20