I have an Html.DropDownListFor with BootStrap that is not left justifying like the Html.TextBoxFor in my form. I've tried both the "pull-left" and "text-left" with no luck. When I look at page with the Developer Tools there doesn't look to be anything that I can see causing a problem.
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Submitter Information</h3>
</div>
<div class="panel-body">
<div class="row form-group">
#Html.LabelFor(m => m.EmployeeId, new { #class = "col-md-4 control-label text-right" })
#Html.TextBoxFor(m => m.EmployeeId, new { #class = "col-md-8 form-control", #readonly = "true" })
</div>
<div class="row form-group">
#Html.LabelFor(m => m.EmployeeName, new { #class = "col-md-4 control-label text-right" })
#Html.TextBoxFor(m => m.EmployeeName, new { #class = "col-md-8 form-control", autofocus = true, #placeholder = "Employee Name" })
</div>
<div class="row form-group">
#Html.LabelFor(m => m.EmployeeEmail, new { #class = "col-md-4 control-label text-right" })
#Html.TextBoxFor(m => m.EmployeeEmail, new { #class = "col-md-8 form-control", #placeholder = "Email Address" })
</div>
<div class="row form-group">
#Html.LabelFor(m => m.SelectedEmployeeCo, new { #class = "col-md-4 control-label text-right" })
<div class="col-md-8 pull-left">
#Html.DropDownListFor(x => x.SelectedEmployeeCo,
new SelectList(Model.Companies, "Co", "Name"),
"-- Select Company --",
new {#class = "form-control text-left" })
</div>
</div>
</div>
</div>
I changed some things around and this should have been obivious to me since I was doing the same thing for the other TextBoxFor. I ended up moving the column class into the CSS directly on the DropDownListFor instead of in a separate div. I would have thought it would render the same but it doesn't. So, the point here is to be consistent. Either wrap each control in a div with the column CSS or apply the CSS directly on the control.
This is how I fixed it.
<div class="row form-group">
#Html.LabelFor(m => m.SelectedEmployeeCo, new { #class = "col-md-4 control-label text-right" })
#Html.DropDownListFor(x => x.SelectedEmployeeCo,
new SelectList(Model.Companies, "Co", "Name"),
"-- Select Company --",
new { #class = "col-md-8 form-control pull-left" })
</div>
Related
I'm making Hotel management web app, and working on part where i need to add rooms ,problem is with dropdown menu, while adding knew code , I don't know why my dropdown menu stopped working ,it wokrked perfectly before but when added another part of code, dropdown just stoped wokring(when i click on it it wont drop), i removed code that i added before but a dropdown menu still doesent work.I added the part with the dropdown menu below
**index.cshtlm**
#model HotelManagement.ViewModel.RoomViewModel
{
ViewBag.Title = "Index";
}
<pre>
<div id="divAddRoom" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Room</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="form-group ">
</pre>
#Html.LabelFor(model => model.RoomNumber)
#Html.TextBoxFor(model => model.RoomNumber, new { #class = "form-control", id = "txtRoomNumber" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.RoomPrice)
#Html.TextBoxFor(model => model.RoomPrice, new { #class = "form-control", id = "txtRoomPrice" })
</div>
<div class="form-group ">
#Html.LabelFor(model => model.BookingStatusId)
#Html.DropDownListFor(model => model.BookingStatusId, #Model.ListOfBookingStatus, new { #class = "form-control", id = "ddBookingStatus" })
</div>
<div class="form-group ">
#Html.LabelFor(model => model.RoomTypeId)
#Html.DropDownListFor(model => model.RoomTypeId, #Model.ListOfRoomType, new { #class = "form-control", id = "ddRoomType" })
</div>
<div class="form-group ">
#Html.LabelFor(model => model.RoomCapacity)
#Html.TextBoxFor(model => model.RoomCapacity, new { #class = "form-control", id = "txtRoomCapacity" })
</div>
<div class="form-group ">
#Html.LabelFor(model => model.RoomDescription)
#Html.TextBoxFor(model => model.RoomDescription, new { #class = "form-control", id = "txtRoomDescription" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.RoomImage)
<input id="UpLoadImage" type="file" class="form-control" name="roomImage" title="Load Image" onchange="DisplayImage(this)" />
<img id="imgRoom" height="200" width="280" style="border:solid" />
</div>
</div>
</div>
<div class="modal-footer">
<button id="btnSave" type="button" class="btn btn-success">Save</button>
<button type="button" data-dismiss="modal" class="btn btn-danger">Close</button>
</div>
</div>
</div>
Room_controler
enter code here
public ActionResult Index(){
RoomViewModel objRoomViewModel = new RoomViewModel();
objRoomViewModel.ListOfBookingStatus = (from obj in objHotelDbEntities.BookingStatus
select new SelectListItem()
{
Text = obj.BookingStatus,
Value = obj.BookingStatusId.ToString()
}).ToList();
objRoomViewModel.ListOfRoomType = (from obj in objHotelDbEntities.RoomTypes
select new SelectListItem()
{
Text = obj.RoomTypeName,
Value = obj.RoomTypeId.ToString()
}).ToList();
return View(objRoomViewModel);
}
image of the problem
I am designing an edit form using MVC 5 Razor. I want the input controls to fill the whole blank width as shown in the picture but it is not working. see image here.
Page here
I have put controls inside table dimensions. One dimension is for the label and the other dimension is for input editor (HTML Helper).
I have tried to override the form-control width with the following css class but no success:
.form-control {
width: 100%!important;
}
and even made another css class
.newinputwidth {
width: 400px!important;
}
but it does not change the width of input.
The full MVC code is here.
#model test2.Models.CaseReport
<style>
.form-control {
width: 100%!important;
}
.newinputwidth {
width: 400px!important;
}
</style>
<h2>Edit</h2>
<div class="container">
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="row">
<div class="col-lg-12 col-md-12 col-xs-12">
<table id="dt" class="table table-condensed table-responsive table-bordered" width="100%" cellspacing="0">
<tr>
<td>Main Id</td>
<td>
#Html.EditorFor(model => model.CaseReportId, new { htmlAttributes = new { #class = "newinputwidth" } })
</td>
</tr>
<tr>
<td>Location</td>
<td>
#Html.EditorFor(model => model.Location, new { htmlAttributes = new { #class = "form-control" } })
</td>
</tr>
<tr>
<td>Disease </td>
<td>
#Html.EditorFor(model => model.ReportDate, new { htmlAttributes = new { #class = "form-control" } })
</td>
</tr>
</table>
</div>
<div class="row col-lg-12 col-md-12 col-xs-12 text-center">
<div>
<div>
#Html.Action("_DetailsIndex", new { id = Model.CaseReportId })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
<div>
#Html.ActionLink("Back to List", "Index")
</div>
</div>
}
</div>
In bootstrap, you put blank controls in a container class and apply custom css on it. That will take care of the width of the blank controls. Now, sometimes even when you set container class's width, it does not mean it is responsive or it really makes controls width so short! To achieve responsive desired behavior readable to users set css for each control and apply # style="100% !important; min-width:300px;".
Here is an example:
#using (Html.BeginForm("Register", "Account", FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{ <div class="container" style="width:40%; margin:6%">
<h4 style="color:darkorange">Register</h4>
<div class="row text-center">
<h5 style="color:tomato">#ViewBag.Message</h5>
</div>
#Html.AntiForgeryToken()
<div class="form-horizontal">
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.FirstName, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { #class = "form-control", #placeholder = "First Name", #style = "width:100% !important; min-width:180px;" } })
#Html.ValidationMessageFor(model => model.FirstName, "", new { #class = "text-danger" })
</div>
</div>
</div>
</div>
}
Since you're using Bootstrap, I would suggest abandoning the table completely for this type of layout.
You should be able to achieve this with the grid system using a horizontal form:
http://getbootstrap.com/css/#forms-horizontal
<div class="row form-horizontal">
<div class="col-md-12">
<div class="form-group">
#Html.LabelFor(model => model.CaseReportId, htmlAttributes: new { #class = "control-label col-md-3" })
<div class="col-md-9">
#Html.EditorFor(model => model.CaseReportId, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Location, htmlAttributes: new { #class = "control-label col-md-3" })
<div class="col-md-9">
#Html.EditorFor(model => model.Location, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.ReportDate, htmlAttributes: new { #class = "control-label col-md-3" })
<div class="col-md-9">
#Html.EditorFor(model => model.ReportDate, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
</div>
</div>
If you really want to use a table, I noticed you have a table-responsive class on the table element. This is meant to be used on a parent (wrapper) div.
http://getbootstrap.com/css/#tables-responsive
<div class="table-responsive">
<table class="table">
...
</table>
</div>
I'm having some issues working with bootstrap. I'm a little confused right now. I need to add a form on the right side of a photo in Asp.net MVC. I have a render body on my main page and then in the other view I have this bootstrap code:
#using (Html.BeginForm("EditarUtilizador", "Account", null, FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
System.Diagnostics.Debug.WriteLine(#Html.DisplayFor(modelItem => modelItem.ImagePath));
<div class="form-horizontal">
<h4>Editar Perfil Pessoal</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<fieldset class="col-md-3">
#if (Model.ImagePath != null)
{
<img src="~/Images/#Html.DisplayFor(modelItem => modelItem.ImagePath)" width="150" height="150" />
}
else
{
<img src="~/StaticImages/default-user-image.png" width="150" height="150" />
}
<div class="editor-field">
<input id="ImagePath" title="Upload a product image"
type="file" name="file" />
</div>
</fieldset>
<div class="form-group" >
#Html.LabelFor(m => m.Utilizador, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.DisplayFor(m => m.Utilizador, new { #class = "form-control"})
#Html.ValidationMessageFor(model => model.Utilizador, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.Password, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.EditorFor(m => m.Password, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Password, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.NovaPassword, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.EditorFor(m => m.NovaPassword, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Password, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.Email, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.DisplayFor(m => m.Email, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Email, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.Telemóvel, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.EditorFor(m => m.Telemóvel, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Telemóvel, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.DataNascimento, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.EditorFor(m => m.DataNascimento, new { #class = "form-control", type = "date", })
#Html.ValidationMessageFor(model => model.DataNascimento, "", new { #class = "text-danger" })
</div>
What I have at the moment is this:
I want to form to appear on the right, but in my case it appears below the image.
Because <div> elements are block-level, they will stack on top of one another by default. Alter the CSS to get what you desire.
Using Bootstrap Grid Mechanism
You can align content in the following manner
#Html.BeginForm(){
<div class="row">
<div class="col-md-8">
Add the input fields in this column
</div>
<div class="col-md-4">
Add the image portion here
</div>
</div>
}
The maximum value of column in Bootrap grid is 12, you can divide this value into individual columns like I did. You can tweak the col-md-* values according to your preference.
You can learn more about the bootstrap Grid in the following link.
https://getbootstrap.com/examples/grid/
I really don't know what I'm doing wrong. I want my textboxes with same size of my buttons below. I already tried change a lot in the cshtml but without success.
Below my cshtml file:
#model SomeModel.Models.LoginViewModel
<div class="row">
<div class="col-md-8 col-sm-12 col-xs-12">
<section id="loginForm">
#using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
#Html.AntiForgeryToken()
<hr />
#Html.ValidationSummary(true)
<div class="form-group">
#Html.LabelFor(m => m.UserName, new { #class = "col-md-2 control-label" })
<div class="col-md-12">
#Html.TextBoxFor(m => m.UserName, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.UserName)
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.Password, new { #class = "col-md-2 control-label" })
<div class="col-md-12">
#Html.PasswordFor(m => m.Password, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Password)
</div>
</div>
<div class="form-group">
<div class="col-sm-12 col-xs-12">
<button type="submit" class="btn btn-success btn-block">Entrar</button>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-sm-12 col-xs-12 visible-sm visible-xs">
<button type="submit" class="btn btn-primary btn-block">Ainda Não Tenho Conta</button>
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-sm-12 col-xs-12 visible-sm visible-xs">
<button type="submit" class="btn btn-info btn-block">Esqueci Meu Usuário Ou Senha</button>
</div>
</div>
<p>
#Html.ActionLink("Register", "Register") if you don't have a local account.
</p>
}
</section>
</div>
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
What am I doing wrong?
The default MVC5 template has a css rule in Site.css:
input, select, textarea { max-width: 280px; }
I usually remove this rule.
It causes problems with Bootstrap v3 input group where the input box does not extend to its container's width.
I've got display problem when using http://eternicode.github.io/bootstrap-datepicker in Bootstrap 3.
How to get datepicker in this picture?
I'm using MVC 5 with auto generated views
Create.cshtml
<div class="form-group">
#Html.LabelFor(model => model.TerminateDate, new { #class = "control-label col-md-2" })
<div class="col-md-10">
<div class="input-group date" id="dp3">
#Html.EditorFor(model => model.TerminateDate, new { htmlAttributes = new { #class = "form-control datepicker", #readonly = "readonly" } })
<span class="btn btn-default input-group-addon">
<i class="glyphicon glyphicon-calendar"></i>
</span>
#Html.ValidationMessageFor(model => model.TerminateDate)
</div>
</div>
</div>
UPDATE:
Now it looks like better but a little long, how to set the length?
<div class="form-group">
#Html.LabelFor(model => model.TerminateDate, new { #class = "control-label col-md-2" })
<div class="col-md-4">
<div class="input-group date">
#Html.EditorFor(model => model.TerminateDate, new { htmlAttributes = new { #class = "form-control date", #readonly = "readonly" } })
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
#Html.ValidationMessageFor(model => model.TerminateDate)
</div>
</div>
</div>
Hope this helps. I just added some class and change some tag. It will look like this
<div class="form-group">
#Html.LabelFor(model => model.TerminateDate, new { #class = "control-label col-md-2" })
<div class="input-group col-md-10">
<input type="text" class="form-control input-group date" id="dp3">
#Html.EditorFor(model => model.TerminateDate, new { htmlAttributes = new { #class = "form-control datepicker", #readonly = "readonly" } })
<span class="btn btn-default input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
#Html.ValidationMessageFor(model => model.TerminateDate)
</div>
</div>
Update:Take a look at the "Column sizing" subsection here
Try to follow this format:
<div id="datetimepicker1" class="input-append date">
<input data-format="dd/MM/yyyy hh:mm:ss" type="text"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar">
</i>
</span>
</div>
The default site.css created when you make a new project has a max-width set on the input element:
/* Set width on the form input elements since they're 100% wide by default */
input,
select,
textarea {
max-width: 280px;
}
Remove or comment this out and your col-md-10 will work perfect.