I'm struggling to style my links properly when combining CSS and Bootstrap with MVC. It seems like @Html.ActionLink is needed for redirection, but styling remains a challenge. Is there a way to style it effectively?
When using pure CSS, everything works fine:
<div class="mx-auto order-0">
<a class="navbar-brand mx-auto" href="#">LIBRARY</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</div>
This is how I've set it up in MVC:
<div class="mx-auto order-0">
<a class="navbar-brand mx-auto" href="/Index">
@Html.ActionLink("Library", "Index", "MyTemplate", null, new { @class = "mx-auto order-0" })
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</div>
Even after testing this setup on MVC, the styling issue persists:
@Html.ActionLink("Library", "Index", "MyTemplate", null, new { @class = "mx-auto order-0" })
Here's how my index.cshtml file is structured:
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_MasterLayout.cshtml";
}
<h2>Index</h2>
And here's the controller code:
public class MyTemplateController : Controller
{
// GET: MyTemplate
public ActionResult Index()
{
return View("Index");
}
public ActionResult About()
{
return View("About");
}
public ActionResult Contact()
{
return View("Contact");
}
}
}
In the HTML file:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<title>@ViewBag.title</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="Content/bootstrap.css">
<link rel="stylesheet" type="text/css" href="Content/style.css">
<link href="https://use.fontawesome.com/releases/v5.11.2/css/all.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap" rel="stylesheet"...
The styling issue persists despite various attempts. While adding inline styles could solve the problem temporarily, I prefer maintaining all styles in style.css for better organization. Any advice on resolving this dilemma would be greatly appreciated.