Introduction
Today, I will show you how to develop an ASP.NET MVC 5 web application that has multi-platform UI support (like Mobile View and Desktop View).
Mobile View v/s Desktop View
The User Interface for building a mobile View is very different than building desktop Views. So, ASP.NET MVC can help us to fulfill it using 51Degrees.mobi library package.
Description
The start page of this application will display all Cricket player's achievements and we have another page to filter the achievements based on selection of the player name. I have two types of UI Views: Desktop View and Mobile View. We use static data to display on web pages for mobile specific Views.
If we have two pages with the same information, we have to retrieve a particular View based on the platform and browser . If the requests come from a smart phone browser, the mobile View will come, otherwise the application will come in the normal View for desktop/laptop browser.
To detect the platform and browser from where the request is coming at server, I used 51Degrees.mobi to detect the user details. Then, to run the application for mobile View, we need emulator for mobile or we can use browser which can behave like a browser on mobile. For this purpose, I am using Mozilla Firefox browser to test both kinds of Views.
Process to develop this application using ASP.NET MVC 5.
Step 1
Create a sample application by selecting ASP.NET MVC web application template and give project a name, such as SatyajQueryMobileMvc, and click "OK".
Select project template as internet application. Visual Studio 2013 adds SatyajQueryMobileMvc project in the solution, as shown in the screenshot.
Step 2
Install 51Degrees.mobi
51Degrees.mobi is a library device package. By using this, we will get details of library device data, accurate screen sizes, model information which are all available to the application.
Click on "Tools" in Menu bar, go to "Library Package Manager" and the choose "Manage NuGet Packages for Solution" option, as shown in the below screenshot.
Type 51Degrees.mobi in search textbox and the "Install" option will show up, download and install it.
Now, you will be able to see “51Degrees.config” file in your project.
It will create a “Mobile” folder in application. I will delete that unnecessary folder and i have our mobile view in Views folder only.
Also, we have to comment out some code in 51Degrees.config as it will redirect the request from mobiles to “~/mobile/default.aspx”.
Commented code ref by me -
- <redirect devicesFile="" timeout="20" firstRequestOnly="true"
- originalUrlAsQueryString="false" mobileHomePageUrl="~/Mobile/Default.aspx"
- mobilePagesRegex="/(Mobile|Tablet)/">
- <locations>
- <clear />
- <location name="noredirect" url="" matchExpression="" enabled="true">
- <add property="Url" matchExpression="[&|\?]noredirect" enabled="true" />
- </location>
- <location name="Mobile" url="~/Mobile/Default.aspx" matchExpression=""
- enabled="true">
- <add property="IsMobile" matchExpression="True" enabled="true" />
- <add property="IsTablet" matchExpression="False" enabled="true" />
- </location>
- <location name="Tablet" url="~/Tablet/Default.aspx" matchExpression=""
- enabled="true">
- <add property="IsTablet" matchExpression="True" enabled="true" />
- </location>
- </locations>
- </redirect>
It can be done using a second way also.
Go to top menu “TOOLS > Library Package Manager > Package Manager Console”.
It will open a console window. Now, you need to run the following command:
Install-Package 51Degrees.mobi
Please visit site here to know How it works.
http://51degrees.codeplex.com/
Step 3
WORKING WITH MODELS.
Create a Model Class file named “Player.cs”;
Code Ref
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
-
- namespace SatyajQueryMobileMvc.Models
- {
- public class Player
- {
- public int PlayerId { get; set; }
- public string PlayerName { get; set; }
- }
- }
Code Description
Two entities PlayerId and PlayerName are declared publicly to access in other class files. Then, we created a Model Class file named “Achieve.cs”.
Code Ref
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
-
- namespace SatyajQueryMobileMvc.Models
- {
- public class Achieve
- {
- public int AchieveId { get; set; }
- public string AchieveName { get; set; }
- public string AchieveDescription { get; set; }
- public Player PlayerAchieve { get; set; }
- }
- }
Code Description
The entities AchieveId, AchieveName, AchieveDescription, PlayerAchieve are declared here publicly to access the data in other class files. Then we created a Model Class file named “DataRepository.cs”.
Code Ref
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
-
- namespace SatyajQueryMobileMvc.Models
- {
- public class DataRepository
- {
- public List<Achieve> GetAchieves()
- {
- List<Achieve> Achieves = new List<Achieve>{
- new Achieve () { AchieveId = 1, AchieveName = "MS DHONI'S ICC ICC WORLD CUP", AchieveDescription = "MS DHONI has ICC ICC WORLD CUP.",
- PlayerAchieve = new Player () { PlayerId = 1, PlayerName = "MS DHONI"}},
-
- new Achieve () { AchieveId = 2, AchieveName = "MS DHONI'S ICC ICC CHAMPIONS TROPHY", AchieveDescription = "MS DHONI has ICC CHAMPIONS TROPHY.",
- PlayerAchieve = new Player () { PlayerId = 1, PlayerName = "MS DHONI"}},
-
- new Achieve () {AchieveId = 3, AchieveName = "SOURAV GANGULY'S ICC ICC WORLD CUP", AchieveDescription = "SOURAV GANGULY has no ICC WORLD CUP.",
- PlayerAchieve = new Player () {PlayerId = 2, PlayerName = "SOURAV GANGULY"}},
-
- new Achieve () {AchieveId = 4, AchieveName = "SOURAV GANGULY'S ICC ICC CHAMPIONS TROPHY", AchieveDescription = "SOURAV GANGULY has ICC CHAMPIONS TROPHY.",
- PlayerAchieve = new Player () {PlayerId = 2, PlayerName = "SOURAV GANGULY"}},
-
- new Achieve () {AchieveId = 5, AchieveName = "MOHAMMAD AZHARUDDIN'S ICC ICC WORLD CUP", AchieveDescription = "MOHAMMAD AZHARUDDIN has no ICC WORLD CUP.",
- PlayerAchieve = new Player () {PlayerId = 3, PlayerName = "MOHAMMAD AZHARUDDIN"}},
-
- new Achieve () {AchieveId = 6, AchieveName = "MOHAMMAD AZHARUDDIN'S ICC ICC CHAMPIONS TROPHY", AchieveDescription = "MOHAMMAD AZHARUDDIN has no ICC CHAMPIONS TROPHY.",
- PlayerAchieve = new Player () {PlayerId = 3, PlayerName = "MOHAMMAD AZHARUDDIN"}},
-
- new Achieve () {AchieveId = 7, AchieveName = "KAPIL DEV'S ICC ICC WORLD CUP", AchieveDescription = "KAPIL DEV has ICC WORLD CUP.",
- PlayerAchieve = new Player () {PlayerId = 4, PlayerName = "KAPIL DEV"}},
-
- new Achieve () {AchieveId = 8, AchieveName = "KAPIL DEV'S ICC ICC CHAMPIONS TROPHY", AchieveDescription = "KAPIL DEV has ICC CHAMPIONS TROPHY.",
- PlayerAchieve = new Player () {PlayerId = 4, PlayerName = "KAPIL DEV"}}
- };
-
- return Achieves;
- }
-
-
- public List<Player> GetPlayers()
- {
- return new List<Player> {
- new Player () { PlayerId = 1, PlayerName = "MS DHONI"},
- new Player () {PlayerId = 2, PlayerName = "SOURAV GANGULY"},
- new Player () { PlayerId = 3, PlayerName = "MOHAMMAD AZHARUDDIN"},
- new Player () { PlayerId = 4, PlayerName = "KAPIL DEV"}
- };
- }
- }
- }
Code Description
In DataRepository.cs, we have used Player.cs and Achieve.cs class references and their entities to insert data successfully. Use Player class as list generic class to add some records to filter data by using the entities defined in this class.
- public List<Player> GetPlayers()
- {
- return new List<Player> {
- new Player () { PlayerId = 1, PlayerName = "MS DHONI"},
- new Player () {PlayerId = 2, PlayerName = "SOURAV GANGULY"},
- new Player () { PlayerId = 3, PlayerName = "MOHAMMAD AZHARUDDIN"},
- new Player () { PlayerId = 4, PlayerName = "KAPIL DEV"}
- };
- }
Here, GetPlayers() is the user defined function used to deliver this record to Views for filtering data as per selection of these records.
- public List<Player> GetPlayers()
Here, Achieve.cs class files used their entities to put some records details as per selection of value of entities defined in Player.cs class file.
- public List<Achieve> GetAchieves()
- {
- List<Achieve> Achieves = new List<Achieve>{
- new Achieve () { AchieveId = 1, AchieveName = "MS DHONI'S ICC ICC WORLD CUP", AchieveDescription = "MS DHONI has ICC ICC WORLD CUP.",
- PlayerAchieve = new Player () { PlayerId = 1, PlayerName = "MS DHONI"}},
-
- new Achieve () { AchieveId = 2, AchieveName = "MS DHONI'S ICC ICC CHAMPIONS TROPHY", AchieveDescription = "MS DHONI has ICC CHAMPIONS TROPHY.",
- PlayerAchieve = new Player () { PlayerId = 1, PlayerName = "MS DHONI"}},
-
- new Achieve () {AchieveId = 3, AchieveName = "SOURAV GANGULY'S ICC ICC WORLD CUP", AchieveDescription = "SOURAV GANGULY has no ICC WORLD CUP.",
- PlayerAchieve = new Player () {PlayerId = 2, PlayerName = "SOURAV GANGULY"}},
-
- new Achieve () {AchieveId = 4, AchieveName = "SOURAV GANGULY'S ICC ICC CHAMPIONS TROPHY", AchieveDescription = "SOURAV GANGULY has ICC CHAMPIONS TROPHY.",
- PlayerAchieve = new Player () {PlayerId = 2, PlayerName = "SOURAV GANGULY"}},
-
- new Achieve () {AchieveId = 5, AchieveName = "MOHAMMAD AZHARUDDIN'S ICC ICC WORLD CUP", AchieveDescription = "MOHAMMAD AZHARUDDIN has no ICC WORLD CUP.",
- PlayerAchieve = new Player () {PlayerId = 3, PlayerName = "MOHAMMAD AZHARUDDIN"}},
-
- new Achieve () {AchieveId = 6, AchieveName = "MOHAMMAD AZHARUDDIN'S ICC ICC CHAMPIONS TROPHY", AchieveDescription = "MOHAMMAD AZHARUDDIN has no ICC CHAMPIONS TROPHY.",
- PlayerAchieve = new Player () {PlayerId = 3, PlayerName = "MOHAMMAD AZHARUDDIN"}},
-
- new Achieve () {AchieveId = 7, AchieveName = "KAPIL DEV'S ICC ICC WORLD CUP", AchieveDescription = "KAPIL DEV has ICC WORLD CUP.",
- PlayerAchieve = new Player () {PlayerId = 4, PlayerName = "KAPIL DEV"}},
-
- new Achieve () {AchieveId = 8, AchieveName = "KAPIL DEV'S ICC ICC CHAMPIONS TROPHY", AchieveDescription = "KAPIL DEV has ICC CHAMPIONS TROPHY.",
- PlayerAchieve = new Player () {PlayerId = 4, PlayerName = "KAPIL DEV"}}
- };
-
- return Achieves;
- }
In this class, the Player class reference is used for accurate filtering of data.
- List<Achieve> Achieves = new List<Achieve>{
- new Achieve () { AchieveId = 1, AchieveName = "MS DHONI'S ICC ICC WORLD CUP", AchieveDescription = "MS DHONI has ICC ICC WORLD CUP.",
- PlayerAchieve = new Player () { PlayerId = 1, PlayerName = "MS DHONI"}}
Here, MS DHONI is a Player in Player.cs and is shown in the dropdown list. The records will be shown as defined in Achieve.cs.
- AchieveName = "MS DHONI'S ICC ICC WORLD CUP", AchieveDescription = "MS DHONI has ICC ICC WORLD CUP." ---> PlayerName = "MS
Here, GetAchieves is the user defined function in Achieve.cs class file for showing details of records as per selection of values in GetPlayers user defined function in Player.cs class file.
Step 4
Working with "PlayerModels" folder.
Create a new folder named “PlayerModels”.
Then, create class file named “PlayerAchieve.cs”.
Code Ref
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using SatyajQueryMobileMvc.Models;
-
- namespace SatyajQueryMobileMvc.PlayerModels
- {
- public class PlayerAchieve
- {
- public int SelectedPlayerId = -1;
- public List<Player> AllPlayers { get; set; }
- public List<Achieve> AllAchieves { get; set; }
- }
- }
Code Description
Here, I am using two namespaces to access Model class files, which are Player, Achieve and DataRepository classes.
- using System.Web;
-
- using SatyajQueryMobileMvc.Models;
Here are the generic list classes with properties for future references in Dropdown list and details list in Views.
- public int SelectedPlayerId = -1;
Step 5
Working with Controllers.
Create a Controller class file named “AchieveController.cs”;
Code Ref
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using SatyajQueryMobileMvc.Models;
- using SatyajQueryMobileMvc.PlayerModels;
-
- namespace SatyajQueryMobileMvc.Controllers
- {
- public class AchieveController : Controller
- {
- public ActionResult Index()
- {
- return View();
- }
-
- DataRepository _repository = new DataRepository();
-
- public ActionResult AllAchieves()
- {
- List<Achieve> achieveModel = new List<Achieve>();
- achieveModel = _repository.GetAchieves();
- return View(achieveModel);
- }
-
- public ActionResult PlayersWiseAchieves()
- {
- PlayerAchieve pa = new PlayerAchieve();
- pa.AllPlayers = _repository.GetPlayers();
- pa.AllAchieves = _repository.GetAchieves();
- return View(pa);
- }
-
- }
- }
Code Description
Here I using two namespaces to Access Models and PlayerModels class files that is Player , Achieve, DataRepository and PlayerAchieve classes and their respected entities.
DataRepository class creates an object named “_repository” using new keyword.
Here two Important controller action methods defined here.
- public ActionResult AllAchieves()
- {
- List<Achieve> achieveModel = new List<Achieve>();
- achieveModel = _repository.GetAchieves();
- return View(achieveModel);
- }
-
- public ActionResult PlayersWiseAchieves()
- {
- PlayerAchieve pa = new PlayerAchieve();
- pa.AllPlayers = _repository.GetPlayers();
- pa.AllAchieves = _repository.GetAchieves();
- return View(pa);
- }
In AllAchieves action method using the Achieve class method called GetAchieves , The details of data in DataRepository class file will be fetched.
- List<Achieve> achieveModel = new List<Achieve>();
- achieveModel = _repository.GetAchieves();
- return View(achieveModel);
In PlayersWiseAchieves action method using the PlayerAchieve class and reference classes defined in PlayerAchieve that is Player and Achieve class’s methods that is GetPlayers and GetAchieves defined to access dropdown list data and details data . The details of data in DataRepository class file will be fetched.
- public ActionResult PlayersWiseAchieves()
- {
- PlayerAchieve pa = new PlayerAchieve();
- pa.AllPlayers = _repository.GetPlayers();
- pa.AllAchieves = _repository.GetAchieves();
- return View(pa);
- }
In the end return View taking corresponding class object for view references.
- return View(achieveModel);
-
- return View(pa);
Step 6
WORKING WITH VIEWS.
Create a View cshtml file named “AllAchieves.cshtml” in Achieve folder of Views folder;
Code Ref
- @model IEnumerable<SatyajQueryMobileMvc.Models.Achieve>
-
- @{
- ViewBag.Title = "All Players Achieves";
- }
-
- <table>
- <tr>
- <td style="width: 20%; text-align: left;">
- <h2 style="color:red">All Achieves</h2>
- </td>
- <td style="width: 90%; text-align:center">
- @Html.ActionLink("Go To Players wise Achieves", "PlayersWiseAchieves", "", new { style = "font-size:20px; color:red;font-style:oblique;font-size:large" })
- </td>
- </tr>
- </table>
- <table>
- <tr>
- <th>
- Achieve Name
- </th>
- <th>
- Achieve Description
- </th>
- </tr>
-
- @foreach (var item in Model)
- {
- <tr>
- <td style="color:blue; font-style: oblique">
- @Html.DisplayFor(modelItem => item.AchieveName)
- </td>
- <td style="color:green; font-style: oblique">
- @Html.DisplayFor(modelItem => item.AchieveDescription)
- </td>
- </tr>
- }
- </table>
Code Description
This will be the start page view of this application.
We have to add namespace to get Achieve Class data details.
- @model IEnumerable<SatyajQueryMobileMvc.Models.Achieve>
For this view the title will be shown as
- ViewBag.Title = "All Players Achieves";
Here I assigned foreach loop to show Achieve Name and Achieve Description of Achieve class.
- @foreach (var item in Model)
- {
- <tr>
- <td style="color:blue; font-style: oblique">
- @Html.DisplayFor(modelItem => item.AchieveName)
- </td>
- <td style="color:green; font-style: oblique">
- @Html.DisplayFor(modelItem => item.AchieveDescription)
- </td>
- </tr>
- }
See
- @Html.DisplayFor(modelItem => item.AchieveName
-
- @Html.DisplayFor(modelItem => item.AchieveDescription
Here I using actionlink that will be redirected to PlayersWiseAchieves view and show data according to selection parameters in dropdown list.
- @Html.ActionLink("Go To Players wise Achieves", "PlayersWiseAchieves", "", new { style="font-size:20px; color:red;font-style:oblique;font-size:large" })
TO KNOW DETAILS OF THE FEATURE GO TO MY BLOGS AND ARTICLES etc.
http://www.c-sharpcorner.com/members/satyaprakash-samantaray
Again create a View cshtml file named “PlayersWiseAchieves.cshtml” in Achieve folder of Views folder;
Code Ref
- @model SatyajQueryMobileMvc.PlayerModels.PlayerAchieve
-
- @{
- ViewBag.Title = "Players Wise Achieves";
- SelectList cat = new SelectList(Model.AllPlayers, "PlayerId", "PlayerName");
- }
-
- <h2 style="color:red">Players Wise Achieves</h2>
- <br />
- <table>
- <tr>
- <td style="font-size: 16px; font-style: oblique;color:orangered">
- Select a Player Name:
- </td>
- <td>
- @Html.DropDownListFor(m => m.SelectedPlayerId, cat, "Select Player", new { style = "width:200px; font-size:16px;" })
- </td>
- </tr>
- </table>
-
- <table>
- <tbody id="tblAchieveData"></tbody>
- </table>
-
- <script>
-
- $("#SelectedPlayerId").change(function () {
- var selectedPlayer = $(this).val().trim();
- var allAchieves = @Html.Raw(Json.Encode(Model.AllAchieves));
-
- $('#tblAchieveData').empty();
- var headers = '<tr><th>Achieve Name</th><th>Achieve Description</th></tr>';
- var elements = "";
- for (var i = 0; i < allAchieves.length; i++) {
-
- if(allAchieves[i].PlayerAchieve.PlayerId == selectedPlayer)
- elements = elements + '<tr><td style="color:blue; font-style: oblique">' + allAchieves[i].AchieveName + '</td><td style="color:green; font-style: oblique">' + allAchieves[i].AchieveDescription + '</td></tr>';
-
- }
- if (elements != "")
- $('#tblAchieveData').append(headers + elements);
- });
- </script>
-
- <br />
- <br />
-
- <div style="font-style:oblique ; font-size:large">
- @Html.ActionLink("Go To Achieve Home Page", "AllAchieves", "Achieve", new { style = "font-size:20px;color:red;" })
- </div>
Code Description
We have to add namespace to get PlayerAchieve Class References that is Player and Achieve class details.
@model SatyajQueryMobileMvc.PlayerModels.PlayerAchieve
For this view the title will be shown as
ViewBag.Title = "Players Wise Achieves";
We have to add some player name in Dropdown list
SelectList cat = new SelectList(Model.AllPlayers, "PlayerId", "PlayerName");
Here AllPlayers the Object of Player generic list class in PlayerAchieve class file.
Model.AllPlayers
Here PlayerId and PlayerName the entities in Player class file.
SelectList class represents lists let user select one item.
The Dropddown list designed to get Player names .
- @Html.DropDownListFor(m => m.SelectedPlayerId, cat, "Select Player", new { style="width:200px; font-size:16px;" })
Here cat is the SelectList Class object.
Here SelectedPlayerId is the int variable defined in PlayerAchieve class In PlayerModels folder.
- m => m.SelectedPlayerId, cat, "Select Player"
Here I designed one table to show data details and this id we have to pass in Jquery Script file.
- <table>
- <tbody id="tblAchieveData"></tbody>
- </table>
Here I used Jquery Script file is responsible for to show data.
- <script>
- $("#SelectedPlayerId").change(function () {
- var selectedPlayer = $(this).val().trim();
- var allAchieves = @Html.Raw(Json.Encode(Model.AllAchieves));
-
- $('#tblAchieveData').empty();
- var headers = '<tr><th>Achieve Name</th><th>Achieve Description</th></tr>';
-
- var elements = "";
- for (var i = 0; i < allAchieves.length; i++) {
- if(allAchieves[i].PlayerAchieve.PlayerId == selectedPlayer)
- elements = elements + '<tr><td style="color:blue; font-style: oblique">' + allAchieves[i].AchieveName + '</td><td style="color:green; font-style: oblique">' + allAchieves[i].AchieveDescription + '</td></tr>';
-
- }
- if (elements != "")
- $('#tblAchieveData').append(headers + elements);
- });
- </script>
In first Session I passed SeletcedPlayerId to get data details based on selection of dropdown selection.
- $("#SelectedPlayerId").change(function () {
- var selectedPlayer = $(this).val().trim();
- var allAchieves = @Html.Raw(Json.Encode(Model.AllAchieves));
JSON HELPER CLASS PROVIDES METHODS TO WORK WITH DATA.
ENCODE CONVERTS DATA OBJECTS IN STRING FORMATS.
Json.Encode(Model.AllAchieves));
The PlayerAchieve class Object value passed in ENCODE.
Model.AllAchieves
Then defined table id passed here to design view with heading and details.
- $('#tblAchieveData').empty();
- var headers = '<tr><th>Achieve Name</th><th>Achieve Description</th></tr>';
This part will define you How data details will come as per selection of dropdownlist selection parameter.
With selection of Player name of player class , the achieve name and achieve description of Achieve class will be shown using methods and generic list class properties of PlayerAchieve class.
- var elements = "";
- for (var i = 0; i < allAchieves.length; i++) {
- if(allAchieves[i].PlayerAchieve.PlayerId == selectedPlayer)
- elements = elements + '<tr><td style="color:blue; font-style: oblique">' + allAchieves[i].AchieveName + '</td><td style="color:green; font-style: oblique">' + allAchieves[i].AchieveDescription + '</td></tr>';
- }
If there is data then the table id defined in jquery script tag will show you in proper format with heading and data details using combination of Headers and Elements .
- if (elements != "")
- $('#tblAchieveData').append(headers + elements);
- });
Then I used one Action Link to redirect to Home page / Start page that is “AllAchieves.cshtml” View page.
@Html.ActionLink("Go To Achieve Home Page", "AllAchieves", "Achieve", new { style="font-size:20px;color:red;" })
Step 7
WORKING WITH SHARED FOLDER.
Code Ref(Layout.cshtml)
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <title>@ViewBag.Title - SATYAPRAKASH SAMANTARAY</title>
- <meta name="viewport" content="width=device-width" />
- @Styles.Render("~/Content/css")
- @Scripts.Render("~/bundles/modernizr")
- @Scripts.Render("~/bundles/jquery")
- @*With commenting the Players Wise Achieves not showing player details after selection of specific player name.*@
- </head>
- <body>
- <div id="body">
- <section class="content-wrapper main-content clear-fix">
- @RenderBody()
- </section>
- </div>
- </body>
- </html>
Code Description
The Title tag defined here to add some extra text to whatever title text tab defined in both AllAchieves.cshtml and PlayersWiseAchieves.cshtml.
ViewBag.Title = "All Players Achieves";
ViewBag.Title = "Players Wise Achieves";
<title>@ViewBag.Title - SATYAPRAKASH SAMANTARAY</title>
So browser title tab output must be for AllAchieves.cshtml
All Players Achieves - SATYAPRAKASH SAMANTARAY
So browser title tab output must be for PlayersWiseAchieves.cshtml
Players Wise Achieves - SATYAPRAKASH SAMANTARAY
As per requirement you can customize css content by using this reference path.
@Styles.Render("~/Content/css")
This Scripts class line very important for Jquery Script file defined in PlayersWiseAchieves.cshtml View file.
@Scripts.Render("~/bundles/jquery") @*With commenting the Players Wise Achieves not showing player details after selection of specific player name.*@
Details of Jquery Bundles.
Without this line the Jquery script will not work and the output will not be shown even after selection of player name in drop downlist.
Then renders the portion of content page in body tag.
- <body>
- <div id="body">
- <section class="content-wrapper main-content clear-fix">
- @RenderBody()
- </section>
- </div>
- </body>
Step 8
WORKING WITH 51Degrees.mobi.
After Installation Of This 51Degrees.mobi , How to Find all installation related files like Dll file ?
Follow below mentioned image for references.
Picture 1
Picture 2
Picture 3
Picture 4
Step 9
SET START PAGE AT PAGE LOAD FIRST TIME.
Code Ref
- routes.MapRoute(
- name: "Default",
- url: "{controller}/{action}/{id}",
- defaults: new { controller = "Achieve", action = "AllAchieves", id = UrlParameter.Optional }
- );
Code Description
Here Controller Name : Achieve
Controller Action Method / View Name : AllAchieves
Step 10
How to Configure Asp.net Mvc for mobile specific view ?
Important Code Reference 51Degrees.config which can be modified later for further requirement
- <!--Commented by satya
- <redirect devicesFile="" timeout="20" firstRequestOnly="true"
- originalUrlAsQueryString="false" mobileHomePageUrl="~/Mobile/Default.aspx"
- mobilePagesRegex="/(Mobile|Tablet)/">
- <locations>
- <clear />
- <location name="noredirect" url="" matchExpression="" enabled="true">
- <add property="Url" matchExpression="[&|\?]noredirect" enabled="true" />
- </location>
- <location name="Mobile" url="~/Mobile/Default.aspx" matchExpression=""
- enabled="true">
- <add property="IsMobile" matchExpression="True" enabled="true" />
- <add property="IsTablet" matchExpression="False" enabled="true" />
- </location>
- <location name="Tablet" url="~/Tablet/Default.aspx" matchExpression=""
- enabled="true">
- <add property="IsTablet" matchExpression="True" enabled="true" />
- </location>
- </locations>
- </redirect>
- Commented by satya-->
OUTPUT
The Url is - http://localhost:55041/Achieve/AllAchieves
Click On Go To Players wise Achieves link it will go to Player Wise Achieve Page.
The Url changed to http://localhost:55041/Achieve/PlayersWiseAchieves
The drop down list showing Player Name coming from Palyer class and DataRepository class file.
Now, playerwise achievements page showing Achievement Name and Achievement Description from DataRepository Class and Achieve Class file let the user for proper selection of select player name from dropdown list.
If You click Go To Achieve Home Page it will be redirected to All Achieve Home Page View
The Output is shown below.
The title text of http://localhost:55041/Achieve/AllAchieves
The title text of http://localhost:55041/Achieve/PlayersWiseAchieves
Output of different formats of View in different platforms with images is shown below.
- For Mobile View
- For Tablet View
- For Desktop and Laptop View
MOBILE VIEW FORMAT OF THIS ASP.NET MVC APPLICATION
Mobile View 1
Mobile View 2
TABLET FORMAT OF THIS ASP.NET MVC APPLICATION
Tablet View 1
Tablet View 2
DESKTOP/LAPTOP VIEW FORMAT OF THIS ASP.NET MVC APPLICATION
Desktop/Laptop View 1
Desktop/Laptop View 2
Summary
In this article, we learned the below details.
- How to download and install 51Degrees.mobi library packages .
- Customize the package configuration code in 51Degrees.config.
- Create Asp.net Mvc 5 application using 51Degrees.mobi library package.
- Showing Application in different platforms with adjustable screen size.