它是定義的行爲,因爲ViewLocationFormats和PartialViewLocationFormats的定義如下,首先會查看一個aspx頁面。
ViewLocationFormats = new[] {
"~/Views/{1}/{0}.aspx",
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.aspx",
"~/Views/Shared/{0}.ascx"
};
PartialViewLocationFormats = ViewLocationFormats;
PartialViewLocationFormats應該排除我認爲的aspx定義。覆蓋默認的WebFormViewengine可以解決此問題。請注意,您需要在Application_Start()
方法中註冊此方法
public class ASPXViewEngine: WebFormViewEngine
{
public ASPXViewEngine()
{
base.PartialViewLocationFormats =
new string[]
{
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.ascx"
};
base.AreaPartialViewLocationFormats =
new string[]
{
"~/Areas/{2}/Views/{1}/{0}.ascx",
"~/Areas/{2}/Views/Shared/{0}.ascx",
};
}
}
謝謝艾哈邁德,非常有用! – 2010-07-29 16:45:38