Build a project with using C# and MVC
The site can have any content/theme that you want (be creative). The only requirements are as follows:
1) The site should have at least 2 different routes (for example: home and about routes/pages)
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new Asp.net MVC web application in C# is created using Visual Studio 2017 with name "TechNewsWebApplication".This application contains below details.
NOTE :Images are used for demonstration purpose only.
Solution Explorer :
HomeController.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace TechNewsWebApplication.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
}
}
******************************
Index.cshtml :
@{
ViewBag.Title = "TechNews";
}
<img src="~/Images/apple.png" />
<h1>Apple will launch Iphone 11 and IOS 13 on 10th sep
2019.</h1>
<hr /><hr />
<img src="~/Images/oneplus.jpg"/>
<h1>Oneplus 7T will be launched in 05th Oct 2019 in
India</h1>
<hr /><hr />
<img src="~/Images/amazon.png" />
<h1>Amazon has announced great indian dewali
sell.</h1>
<hr /><hr />
*******************************
_Layout.cshtml :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>@ViewBag.Title - TechNews Pvt Ltd.</title>
<link href="~/Content/Site.css" rel="stylesheet" type="text/css"
/>
<link href="~/Content/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<script
src="~/Scripts/modernizr-2.6.2.js"></script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle"
data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("TechNews Pvt Ltd.", "Index", "Home", new { area =
"" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
@Html.ActionLink("Registration", "Register", "Registration", new {
area = "" }, new { @class = "navbar-brand" })
</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - TechNews Pvt
Ltd.</p>
</footer>
</div>
<script
src="~/Scripts/jquery-1.10.2.min.js"></script>
<script
src="~/Scripts/bootstrap.min.js"></script>
</body>
</html>
******************************
site.css :
body {
padding-top: 50px;
padding-bottom: 20px;
}
/* Set padding to keep content from hitting the edges */
.body-content {
padding-left: 15px;
padding-right: 15px;
}
/* Set width on the form input elements since they're 100% wide
by default */
input[type='text'],input[type='email'],
select{
height: 60px;
width: 300px;
font-size: 22px;
padding: 20px;
margin: 10px;
}
/*style for h1*/
h1{
display:inline;
}
/*style for image*/
img{
height:150px;
width:150px;
padding:10px;
border:2px solid green;
}
/*style for button*/
input[type='submit'], input[type='reset'] {
background-color: lightgreen;
color: maroon;
margin: 10px;
width: 150px;
height: 60px;
}
*****************************
RegistrationController.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace TechNewsWebApplication.Controllers
{
public class RegistrationController : Controller
{
// GET: Registration
public ActionResult Register()
{
return View();
}
}
}
******************************
Register.cshtml :
@{
ViewBag.Title = "Register";
}
<br />
<h1>Register for Event</h1>
<table>
<tr>
<td>Name</td>
<td>
<input type="text" id="txtName" placeholder="Enter Name"
/>
</td>
</tr>
<tr>
<td>Email</td>
<td>
<input type="email" id="txtEmail" placeholder="Enter Email"
/>
</td>
</tr>
<tr>
<td>Select Event</td>
<td>
<select>
<option>Apple 11 launch</option>
<option>Oneplus 7T launch</option>
<option>Amazon Sell</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" />
<input type="reset" />
</td>
</tr>
</table>
******************************
RouteConfig.cs :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace TechNewsWebApplication
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id =
UrlParameter.Optional }
);
}
}
}
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :Index.cshtml
Screen 2 :Register.cshtml
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
Get Answers For Free
Most questions answered within 1 hours.