Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format ASP.Net MVC app for desktop and mobile browser

I am working on an ASP.Net MVC application that with views that I want to be able to format for desktop browsers as well as mobile browsers. Both formats would use the same Controllers and Actions but require different views.

What's the best way to do this? Do I do a browser detect in the Action and then invoke the appropriate view? Does the view do the browser detect and then render itself accordingly? Is there something in between return View(); and when the view actually is processed that I can override?

Thanks

like image 798
Matthew Avatar asked Nov 03 '09 21:11

Matthew


People also ask

Can MVC be used for mobile applications?

MVC (model-view-controller) is considered one of the most popular in the mobile web app development.

Can you mix MVC and Razor pages?

You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder. Razor Pages use the folder structure as a convention for routing requests.

Is ASP.NET MVC discontinued?

ASP.NET MVC is no longer in active development.

What are the 3 main components of an ASP.NET MVC application?

The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller.


2 Answers

ScottHa has this post about targeting multiple devices with ASP.NET MVC addressing that same problem.

I would suggest either in the view or in something between the controller and the view (the ViewEngine...)

like image 198
Arjan Einbu Avatar answered Sep 21 '22 00:09

Arjan Einbu


I'd go with custom attributes stuffing appropriate views/masterpages around the returned Model. We use this tactic heavily for Ajaxification, shouldn't be difficult to extend the concept to mobile.

like image 24
Wyatt Barnett Avatar answered Sep 23 '22 00:09

Wyatt Barnett