Appending ..mobile to end of view name behaving erratically

自闭症网瘾萝莉.ら 提交于 2020-01-15 10:27:48

问题


I am trying to create a view that loads only for mobile sites. Apparently, adding .mobile to a view name so _Layout.cshtml becomes _Layout.Mobile.cshtml causes that view to be loaded if the device is viewed on a mobile. I have got this working for the very first view my VS project uses - _Layout.cshtml, but then in that file it loads @Html.Partial(MVC.Shared.Views._Header, Model), I would have expected the same thing to happen with this, that it would know to load the _Header.Mobile.cshtml view instead, but it doesn't. Does this mean I have to manually change all the references to views to have .Mobile at the end of them in the views? I thought the point of the .Mobile was that it knew automatically to use this?


回答1:


I would say that you would have to load the partial by name for it to work, you are specifying a particular file there.

you could load it using

@Html.Partial("_Header", Model)


来源:https://stackoverflow.com/questions/13342135/appending-mobile-to-end-of-view-name-behaving-erratically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!