I have a problem, it does not return anything to me and it does not enter my controller. Someone knows why
<div class="col-xs-12 input-group input-group-sm">
<span style="padding: 2px 20px 0px 50px;"><strong>Ingrese Código de la Imagen:</strong></span>
<div class="form-validator" style="padding: 2px 10px 0px 350px;">
<div style="float: left;">
<img id="CaptchaImg" src="#Url.Action("ShowCaptchaImage", "Account", new { random = Guid.NewGuid().ToString() })" alt="" />
</div>
<div style="float: left;">
<img alt="" src="" class="invoice img_refresh" id="refresh" onclick="RecargaCaptcha('#Url.Action("ShowCaptchaImage", "Account")');" />
</div>
#Html.TextBoxFor(m => m.PasswordNuevo, new { #class = "form-control input-sm", style = "width:500px;" })
</div>
</div>
My Controller:
[Authorize]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
public CaptchaImageResult ShowCaptchaImage(string random)
{
return new CaptchaImageResult();
}
Related
How can I achieve the following progress bar with a label over to the right with a Bootstrap v5.2 Progress Bar?
I have tried using negative margins and got close, but I'm having problems when the label gets wider due to the text getting longer:
Here is my code to get the above:
Single row (ProgressBarWithName.cshtml):
#{
var valuePercentage = (double)Model.Value / Model.MaxValue * 100;
}
<div class="row m-2" style="height: 50px;">
<div class="col-3 text-white bg-dark h-100 d-flex justify-content-end">
<div class="font-allan align-self-center"><b>#Model.Name</b></div>
</div>
<div class="col-9 h-100">
<div class="row gx-0 progress-container h-100">
<div class="col-11">
<div class="progress h-100">
<div class="progress-bar"
role="progressbar" aria-label="Example with label"
aria-valuenow="#valuePercentage" aria-valuemin="0" aria-valuemax="#Model.MaxValue"
style="width: #valuePercentage%;">
</div>
</div>
</div>
<div class="col-1 progress-label align-self-center">
<b class="#if (valuePercentage > 85){ <text>text-white</text> }">#Model.Value</b>
</div>
</div>
</div>
</div>
All rows (CustomBarChart.cshtml):
<div>
#foreach (var item in Model.Items)
{
await Html.RenderPartialAsync("ProgressBarWithName", item);
}
</div>
And I'm just hard-coding some models for testing purposes:
#{
var stat = new Stat("Some Stat", 40, 100);
var stat1 = new Stat("Some Stat1", 84, 100);
var stat2 = new Stat("Some Stat2", 86, 100);
var stat3 = new Stat("Some Stat3", 10, 100);
var stat4 = new Stat("Some Stat4", 100, 100);
var stats = new Stats(new List<Stat> { stat, stat1, stat2, stat3, stat4 });
await Html.RenderPartialAsync("CustomBarChart", stats);
}
CSS:
.progress-container{
margin-right: -60px;
}
.progress-label{
margin-left: -35px;
width: 0;
}
Essentially, my problem is that the default style of the bootstrap progress bar puts the label in the filled portion of the bar.
What I'm trying to do is put the label on the right side of the entire bar (whether it be the filled portion or the background).
I have tried with float, but since I'm using a row/col setup to get that sort of grid style I'm emulating.
Got it:
<div class="row m-2" style="height: 50px;">
<div class="col-4 text-white bg-gray h-100 d-flex justify-content-end rounded-2 p-2" title="#Model.Name">
<b class="font-sans align-self-center mh-100 w-100 overflow-hidden"
style="text-overflow: ellipsis; white-space: nowrap;">
#Model.Name
</b>
</div>
<div class="col-8 h-100 progress-label-container">
<div class="progress h-100">
<div class="progress-bar"
role="progressbar" aria-label="Example with label"
aria-valuenow="#valuePercentage" aria-valuemin="0" aria-valuemax="#Model.MaxValue"
style="width: #valuePercentage%;">
</div>
</div>
<div class="progress-label">
<b>#Model.Value #Model.Units</b>
</div>
</div>
</div>
.progress-label-container{
position: relative;
}
.progress-label{
position: absolute;
right: 7.5%;
top: 25%;
}
I'm building a website but I have an issue that I can't fix. I have multiple card with information inside that are in columns and each 4 columns, they switch to another row. The problem is that the number of card can change and it's not always divisible by 4. So at the end, I can have less than 4 columns in a row. And when I have les than 4 columns in a row, the displaying is not the same that when I have 4 columns in a row. I know that it's doing that because I use col-sm bootstrap class. It's the only way that I found that is simply responsive. I also tried to use col-sm-3 but the problem is that the website is no more responsive. (See screenshots) By the ways, I use razor views so I can write C# and HTML.
What the displaying do when I use col-sm: Display col-sm
The displaying that I want: Display col-sm-3
The problem of the col-sm-3: Problem of col-sm-3
This is the code of the displaying of my card:
.vehicule-card {
border-radius: 10px;
border: solid 4px #2F3136;
background-color: #333333;
}
.vehicule-cardbody {
height: 5em;
}
.vehicule-name {
background-color: #392A49;
color: #B8BABD;
width: 10em;
margin: auto;
padding: 3px;
border-radius: 10px;
border: solid 4px #2F3136;
}
.vehicule-image {
border-radius: 10px;
border: solid 4px #2F3136;
}
<div class="container-fluid">
<div class="headline">VOITURES COMPACTS</div>
<div class="row">
#foreach (var car in Model.cars)
{
if (counter != 0 && counter % 4 == 0)
{
#:</div>
#:<div class="row">
}
<div class="col-sm-3">
<div class="card p-3 m-2 box-shadow vehicule-card">
<img class="card-img-top vehicule-image" src="#car.ImgPath" alt="Card image cap">
<div class="card-body vehicule-cardbody">
<h2 class="vehicule-name">#car.Name</h2>
</div>
</div>
</div>
counter++;
}
</div>
</div>
Don't try running the code, it will not work because it's a razor view.
Thanks
You should be able to get the layout you want using Bootstrap’s grid system.
Your image for the layout you want is larger than what Bootstrap-4 provides with the container-xl (Bootstap-5 has a container-xxl), but you can create your own xxl container (my example has the max width at 1440px, but you can change that).
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<style>
body {
background-color: #212121;
color: #fff;
}
h1 {
color: #B8BABD;
}
hr {
width: 10%;
border-top: 5px solid #392A49;
}
.container-xxl {
width: 100%;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
#media (min-width:1500px) {
.container-xxl {
max-width: 1440px;
}
}
.vehicule-card {
border-radius: 10px;
border: solid 4px #2F3136;
background-color: #333333;
}
.vehicule-cardbody {
height: 5em;
}
.vehicule-name {
background-color: #392A49;
color: #B8BABD;
width: 100%;
text-align: center;
padding: 3px;
border-radius: 10px;
border: solid 4px #2F3136;
}
.vehicule-image {
border-radius: 10px;
border: solid 4px #2F3136;
}
</style>
<div class="container-xxl">
<h1 class="text-center mt-5">VOITURES COMPACTS</h1>
<hr>
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4">
<div class="col mb-3">
<div class="card p-3 m-2 box-shadow vehicule-card">
<img class="card-img-top vehicule-image" src="https://via.placeholder.com/192x108/FF8F8F/000000.png?text=Blista" alt="Card image cap">
<div class="card-body px-0 vehicule-cardbody">
<h2 class="vehicule-name">Blista</h2>
</div>
</div>
</div>
<div class="col mb-3">
<div class="card p-3 m-2 box-shadow vehicule-card">
<img class="card-img-top vehicule-image" src="https://via.placeholder.com/192x108/FFEE8F/000000.png?text=Dilettante" alt="Card image cap">
<div class="card-body px-0 vehicule-cardbody">
<h2 class="vehicule-name">Dilettante</h2>
</div>
</div>
</div>
<div class="col mb-3">
<div class="card p-3 m-2 box-shadow vehicule-card">
<img class="card-img-top vehicule-image" src="https://via.placeholder.com/192x108/B0FF8F/000000.png?text=Issi" alt="Card image cap">
<div class="card-body px-0 vehicule-cardbody">
<h2 class="vehicule-name">Issi</h2>
</div>
</div>
</div>
<div class="col mb-3">
<div class="card p-3 m-2 box-shadow vehicule-card">
<img class="card-img-top vehicule-image" src="https://via.placeholder.com/192x108/8FD2FF/000000.png?text=Panto" alt="Card image cap">
<div class="card-body px-0 vehicule-cardbody">
<h2 class="vehicule-name">Panto</h2>
</div>
</div>
</div>
<div class="col mb-3">
<div class="card p-3 m-2 box-shadow vehicule-card">
<img class="card-img-top vehicule-image" src="https://via.placeholder.com/192x108/AB8FFF/000000.png?text=Prairie" alt="Card image cap">
<div class="card-body px-0 vehicule-cardbody">
<h2 class="vehicule-name">Prairie</h2>
</div>
</div>
</div>
<div class="col mb-3">
<div class="card p-3 m-2 box-shadow vehicule-card">
<img class="card-img-top vehicule-image" src="https://via.placeholder.com/192x108/FF8FF4/000000.png?text=Rhapsody" alt="Card image cap">
<div class="card-body px-0 vehicule-cardbody">
<h2 class="vehicule-name">Rhapsody</h2>
</div>
</div>
</div>
</div>
</div>
My example code is in plain HTML, but you should be able to reverse it to work with Razor.
I want to make the div a standard size of 330px. But when I do it, the elements in the div will get screwed up.
<div class="col-md-3 m-wthree" style="height:330px;">
<div class="col-m">
<a href="#" data-toggle="modal" data-target="##item.id" class="offer-img">
<img src="#item.productImage" class="img-responsive" alt="" style="width:auto;height:124px;">
<div class="offer"><p><span>Offer</span></p></div>
</a>
<div class="mid-1">
<div class="women">
<h6>#item.productName</h6>
</div>
<div class="mid-2">
<p><label>$#item.productOriginalPrice</label><em class="item_price">$#item.productCurrentPrice</em></p>
<div class="clearfix"></div>
</div>
<div class="add">
<button class="btn btn-danger my-cart-btn my-cart-b " data-id="#item.id" data-name="#item.productName" data-summary="#item.productName" data-price="#item.productCurrentPrice" data-quantity="1" data-image="#item.productImage">Add to Cart</button>
</div>
</div>
</div>
</div>
Problem
With % as height
.m-wthree {
width: 50%;
float: left;
margin-bottom: 2em;
}
.add{
text-align:center;
}
.mid-2 p{
float:left;
font-size:0.9em;
color:#B4B4B4;
}
.mid-2 p em{
font-style:normal;
}
.mid-2 p label{
text-decoration: line-through;
font-weight:400;
margin-right:6px;
}
.mid-2 {
padding: 1em 0;
}
Above is the CSS code for the custom CSS. The CSS all seem ok and does not look like it is affecting anything....
I am converting an web app from HTML with bootstrap to ASP.Net (C#) MVC with Bootstrap. I've moved the index file into the View, I've added to theme (dashboard.css) to the Content directory, I've added my images to the images directory, and I've updated the bundle config file.
When I run the HTML page in Firefox, I get the correct layout with 12 items in a row. When I run it with ASP.Net MVC, I only get 4 items in the row. Everything is very big compared to straight HTML. I am trying to get the 12 items in the row like HTML. This is my first ASP.Net MVC app. Any advice on where I should look next? Here is my View file:
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<ul class="nav nav-justified">
<li><a class="navbar-brand" href="#"><img src="images/Logo-Smaller.png" alt="Jenkins"></a></li>
</ul>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>Services</li>
<li>About</li>
<li>Contact Us</li>
</ul>
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="Search...">
</form>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 col-lg-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active">Products <span class="sr-only">(current)</span></li>
<li>Jenkins Replacement Fans</li>
<li>Manufacturer Fans</li>
<li>Motor Protection</li>
<li>Electric Motor Parts</li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main col-lg-10">
<span class="anchor" id="JFans"></span>
<h3 class="page-header">Jenkins Replacement Fans</h3>
<div class="row placeholders">
<div class="col-xs-6 col-sm-3 col-md-1 col-lrg-1 placeholder">
<img src="images/shrouded.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>shrouded</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/shallow_recess.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Shallow Recess</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/paddle_wheel.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Paddle Wheel</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/flat_backed.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Flat Backed</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/flat_backed.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Flat Backed</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/flat_backed.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Flat Backed</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/shrouded.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>shrouded</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/shallow_recess.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Shallow Recess</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/paddle_wheel.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Paddle Wheel</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/flat_backed.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Flat Backed</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/flat_backed.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Flat Backed</h4>
</div>
<div class="col-xs-6 col-sm-3 col-md-1 col-lg-1 placeholder">
<img src="images/flat_backed.JPG" class="img-responsive" alt="Generic placeholder thumbnail">
<h4>Flat Backed</h4>
</div>
</div>
</
Here is my CSS file:
/*
* Base structure
*/
/* Move down content because we have a fixed navbar that is 50px tall */
body {
padding-top: 65px;
}
.navbar-brand {
max-height: 100%;
height: 100%;
width: auto;
margin: 0 0 0 0;
}
.navbar-brand >img {
max-height: 100%;
height: 100%;
-o-object-fit: contain;
object-fit: contain;
width: auto;
padding-top: 0px;
float: none;
}
.navbar-nav li a {
line-height: 65px;
height: 65px;
padding-top: 0;
}
/*
* Global add-ons
*/
.sub-header {
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
/*
* Top navigation
* Hide default border to remove 1px line.
*/
.navbar-fixed-top {
border: 0;
background-color: #F0F0F0;
}
/*
* Sidebar
*/
/* Hide for mobile, show later */
.sidebar {
display: none;
}
#media (min-width: 768px) {
.sidebar {
position: fixed;
top: 55px;
bottom: 0;
left: 0;
z-index: 1000;
display: block;
padding: 20px;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
background-color: #f5f5f5;
border-right: 1px solid #eee;
}
}
.table td {
text-align:left !important;
}
/* Sidebar navigation */
.nav-sidebar {
margin-right: -21px; /* 20px padding + 1px border */
margin-bottom: 20px;
margin-left: -20px;
}
.nav-sidebar > li > a {
padding-right: 20px;
padding-left: 20px;
}
.nav-sidebar > .active > a,
.nav-sidebar > .active > a:hover,
.nav-sidebar > .active > a:focus {
color: #fff;
background-color: #428bca;
}
/*
* Main content
*/
.main {
padding: 20px;
}
#media (min-width: 768px) {
.main {
padding-right: 40px;
padding-left: 40px;
}
}
.main .page-header {
margin-top: 0;
}
/*
* Placeholder dashboard ideas
*/
.placeholders {
margin-bottom: 30px;
text-align: center;
}
.placeholders h4 {
margin-bottom: 0;
}
.placeholder {
margin-bottom: 20px;
}
.placeholder img {
display: inline-block;
border-radius: 50%;
}
.anchor{
display: block;
height: 85px; /*same height as header*/
margin-top: -85px; /*same height as header*/
visibility: hidden;
}
There is no difference in HTML with bootstrap and MVC with Bootstrap so far you are using the same version of Bootstrap. I have converted many commercial HTML Bootstrap themes into MVC Bootstrap themes and it is pretty straight forward.
First of all you are missing a closing body tag. It could be an issue.
Secondly, do not use MVC Bundles at the moment. Copy all your existing HTML in views and make sure all scripts and CSS is referenced to right path. Write a simple action method that just return the view. Once you get the desired output, you are good to modify HTML with dynamic elements.
Thirdly, make sure there is no padding or margin applied to the div where you are using the following code.
col-sm-9 col-sm-offset-3
In last, use developer tools available in your browser to find out the exact output of HTML page. You can always edit the HTML and get the real time results in many modern browsers.
I am using jquery vaidation in mvc and it is working every where
except in one view which contains other view like so :
#{
Layout = Request.IsAjaxRequest() ? null :"~/Views/Shared/FormsView.cshtml";
}
<div id="indexdiv">
<style>
.ma {
padding-left: 5px;
padding-top: 8px;
}
.blueb {
padding-left: 10px;
padding-bottom: 10px;
padding-top: 8px;
}
.add {
margin-bottom: 5px;
width: 500px;
}
</style>
<div class="btn-danger ma ci" style="height:50px ;">
<h2 class="white" style=" float:left; margin-left:5px ; margin-top:2px; margin-bottom:10px;"> ADDRESSES </h2>
<button id="sh" class="btn btn-primary" style="float:right; margin-right:5px;">
#Ajax.ActionLink(
"Create",
"Create",
"Addresses",
new AjaxOptions
{
UpdateTargetId = "EditDivId",
InsertionMode = InsertionMode.Replace
})
</button>
</div>
<div id="EditDivId">
</div>
<div class="nicdark_space10"></div>
#{ Html.RenderAction("_i"); }
#{ Html.RenderAction("Index", "Emails"); }
#{ Html.RenderAction("Index", "Phones"); }
my create action returns this partial view which where the validation doesn't work :
#model CourseSelection.Models.Address
<style>
.ma {
padding-left: 5px;
padding-top: 8px;
}
.blueb {
padding-left: 10px;
padding-bottom: 10px;
padding-top: 8px;
background-color: green;
}
.add {
margin-bottom: 5px;
width: 500px;
}
.mr {
margin-right: 20px;
}
.link {
color: brown;
}
.link:hover {
color: brown;
}
</style>
#Scripts.Render("~/bundles/jquery")
#using (Ajax.BeginForm("Create", "Addresses", FormMethod.Post, new AjaxOptions
{
UpdateTargetId = "indexdiv",
InsertionMode = InsertionMode.Replace
}, new { #id = "createform22" }))
{
#Html.AntiForgeryToken()
<div id="tt">
<div class="blueb nicdark_bg_blue" style="margin-top:10px;">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="addres">Address</label>
<br />
<input type="text" class="form-control add" id="address1" name="address1" maxlength="100" />
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="type">Type</label>
<br />
#Html.DropDownList("typeid", null, htmlAttributes: new { #class = "form-control" })
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="city">City</label>
<select id="Countries" name="cityid" class="form-control"></select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="county">County</label>
<select id="States" name="countyid" class="form-control"></select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="neighborhood">Neighborhood</label>
<input type="text" placeholder="neighborhood" class="form-control" id="neighborhood" name="neighborhood" />
</div>
</div>
<div class="form-group">
<div class="col-md-1">
<label for="s"></label>
<br />
<input type="submit" value="Create" class="btn btn-primary" id="s1" style="margin-top:6px; width:80px; height:35px;" />
</div>
<div class="col-md-1">
<label for="hi"></label>
<input type="reset" value="Cancel" class="btn btn-danger" id="hi5" style="margin-top:6px; margin-left:3px; width:80px; height:35px;" />
</div>
</div>
</div>
</div>
</div>
}
#section scripts {
<script type="text/javascript">
$(function () {
$.getJSON("/Addresses/cities/List", function (data) {
var items = "<option>Select City</option>";
$.each(data, function (i, country) {
var selected = "";
items += "<option value='" + country.Value + "'>" + country.Text + "</option>";
});
$("#Countries").html(items);
});
$("#Countries").change(function () {
var x = $("#Countries > option:selected").attr("value");
$.getJSON("/Addresses/towns/List/" + x, function (data) {
var items = "<option>Select Town</option>";
$.each(data, function (i, town) {
items += "<option value='" + town.Value + "'>" + town.Text + "</option>";
});
$("#States").html(items);
});
});
});
</script>
}
<script>
$("#hi").click(function () {
$("#tt").hide();
});
$("#createform22").validate({
onkeyup: false,
onclick: false,
rules: {
address1: {
required: true,
email: true
},
},
messages: {
address1: {
required: "Please enter an email",
email: "Email Is not valid"
},
},
errorPlacement: function (error, element) {
swal({ title: "", text: error.text(), imageUrl: "/img/warning.png" });
}
});
</script>
here is my email index view where the validation work :
#{
Layout = Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/empty.cshtml";
}
<style>
.ma {
padding-left: 5px;
padding-top: 8px;
}
.blueb {
padding-left: 10px;
padding-bottom: 10px;
padding-top: 8px;
}
.add {
margin-bottom: 5px;
width: 500px;
}
</style>
<div class="btn-danger ma ci" style="height:50px ;">
<h2 class="white" style=" float:left; margin-left:5px ; margin-top:2px; margin-bottom:10px;"> Emails </h2>
<button id="sh" class="btn btn-primary" style="float:right; margin-right:5px;">
#Ajax.ActionLink(
"Create",
"Create",
"Emails",
new AjaxOptions
{
UpdateTargetId = "EditDivId1",
InsertionMode = InsertionMode.Replace
})
</button>
</div>
<div id="EditDivId1">
</div>
<div class="nicdark_space10"></div>
#{ Html.RenderAction("_i"); }
<script>
</script>
Try to use validations into viewmodels. Client validation in Asp.net