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

2019-08-02 20:09发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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