The function renderBody() not using the .Mobile.cs

2019-08-02 20:05发布

I am using new MVC4 mobile functionality where if you add .Mobile to a view name it renders out the mobile one if it's being viewed on a mobile device. So _Home.cshtml becomes _Home.Mobile.cshtml. This is working when I manually call a view: @Html.Partial("_HeaderNavigation",Model) it loads the mobile version if appropriate.

However when I use renderBody() it loads _Home.cshtml instead of _Home.Mobile.cshtml. I am using Areas, so home.cshtml is in an area.

EDIT

Looking into it further, is it because _Home.Mobile.cshtml is in an area called Home? Does this then not know to get the .mobile version?

3条回答
虎瘦雄心在
2楼-- · 2019-08-02 20:13

I think this might be related to this well know open issue of MVC 4 mobile behind-the scenes-caching - you might try applying this patch: FixedDisplayModes

查看更多
神经病院院长
3楼-- · 2019-08-02 20:21

I found out that the issue was that in the controller for the home Area I was returning the full path e.g. return PartialView(MVC.Home.Home.Views._Home, this.Page); instead of return PartialView("_Home", this.Page);, as Dove told me to do in another question I asked.

查看更多
干净又极端
4楼-- · 2019-08-02 20:29

If Home is a view then it would be quite strange to have an underscore under it. The underscore is historically used for items that will not be displayed by themselves and thus not wanted to be discovered.

Can you test your set with a view called Index say under your area Home and see if that works.

查看更多
登录 后发表回答