Claire
Claire

Reputation: 3773

Appending ..mobile to end of view name behaving erratically

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?

Upvotes: 1

Views: 85

Answers (1)

dove
dove

Reputation: 20674

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)

Upvotes: 1

Related Questions