I have a view: User. In that I have an ascx page : Details I 开发者_如何学Chave a view : Test. I want to access the Details from User from test, using render partial. How can I do that?
<%Html.RenderPartial("Details"); %> doesn`t work in this case.
Either use /views/User/Details or put it in the shared folder.
EDIT
Insert this into Global.asax and call in Application_Start
public static void RegisterViewEngine()
{
ViewEngines.Engines.Clear();
WebFormViewEngine viewEngine = new WebFormViewEngine();
viewEngine.PartialViewLocationFormats = (new[] {
"~/Views/Shared/PartialViews/{0}.ascx",
"~/Views/{1}/PartialViews/{0}.ascx"
}).Concat(viewEngine.PartialViewLocationFormats).ToArray();
ViewEngines.Engines.Add(viewEngine);
}
Then you can create a PartialViews folder in all your Views folders and you can reference partial view without needing to use paths.
So;
- Home
- Home : PartialViews
- Shared
- Shared : PartialViews
Obviously you need to put your partial view into the PartialViews folder for it to be visible. :)
But if you look at the c# code you should be able to work out what it's doing and come up with your own paths etc.
精彩评论