Skip to content

Commit

Permalink
add project and example
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiman Salamah committed Feb 7, 2019
1 parent ea6808d commit 692b254
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 4 deletions.
4 changes: 2 additions & 2 deletions MvcLanguageUrlByRoutingNetFrameWork/App_Start/RouteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static void RegisterRoutes(RouteCollection routes)

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
url: "{language}/{controller}/{action}/{id}",
defaults: new { language = "ar-sa", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ public class HomeController : Controller
{
public ActionResult Index()
{
return View();
var lang = (string)this.RouteData.Values["language"];
switch ((string)this.RouteData.Values["language"])
{
case "ar-sa":
return View("indexar");
case "en-sa":
return View("indexen");
default:
return View("PageNotFound");
}
}

public ActionResult About()
Expand All @@ -26,5 +35,11 @@ public ActionResult Contact()

return View();
}
public ActionResult ChangeLanguage(string Lang, string returnURL)
{
if (returnURL.Length > 1)
return Redirect($"/{Lang}{returnURL.Substring(6, returnURL.Length - 6)}");
else return Redirect(returnURL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\Home\About.cshtml" />
<Content Include="Views\Home\Contact.cshtml" />
<Content Include="Views\Home\Index.cshtml" />
<Content Include="Views\Home\IndexEn.cshtml" />
<Content Include="Views\Account\_ExternalLoginsListPartial.cshtml" />
<Content Include="Views\Account\ConfirmEmail.cshtml" />
<Content Include="Views\Account\ExternalLoginConfirmation.cshtml" />
Expand All @@ -241,6 +241,8 @@
<Content Include="Views\Manage\VerifyPhoneNumber.cshtml" />
<Content Include="Views\Shared\Lockout.cshtml" />
<Content Include="Views\Shared\_LoginPartial.cshtml" />
<Content Include="Views\Home\IndexAr.cshtml" />
<Content Include="Views\Shared\PageNotFound.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
Expand Down
31 changes: 31 additions & 0 deletions MvcLanguageUrlByRoutingNetFrameWork/Views/Home/IndexAr.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@{
ViewBag.Title = "الصفحة الرئيسية";
}

<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="https://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>

<div class="row">
<div class="col-md-4">
<h2>Getting started</h2>
<p>
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
enables a clean separation of concerns and gives you full control over markup
for enjoyable, agile development.
</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Get more libraries</h2>
<p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p>
</div>
<div class="col-md-4">
<h2>Web Hosting</h2>
<p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
<p><a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@{
ViewBag.Title = "PageNotFound";
}

<h2>Page Not Found</h2>

Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@ else
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
@if ((string)ViewContext.RouteData.Values["language"] == "en-sa")
{
<li><a href="@Url.Action("ChangeLanguage","Home",new {Lang="ar-sa",returnURL=ViewContext.HttpContext.Request.Url.PathAndQuery })">عربي</a></li>
}
else
{
<li><a href="@Url.Action("ChangeLanguage","Home",new {Lang="en-sa",returnURL=ViewContext.HttpContext.Request.Url.PathAndQuery })">English</a></li>
}

</ul>
}

0 comments on commit 692b254

Please sign in to comment.