I am working on an ASP.NET, Bootstrap 3 website and have a problem with changing the size of the dropdownlist.
I can change it manually in the CSS to match the size of the other input boxes but I don't want to edit it manually every time I need to change it.
Is there a way to always keep the width the same between the dropdownlist and the other input boxes?
Here is what it is doing:
iPhone 6 vs
iPhone 5: Problem. The problem is that the dropdownlist doesn't get resized within the div.
And here is an example of my code:
<section class="features">
#using (Html.BeginForm("Create", "UsersAdmin", FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
#Html.AntiForgeryToken()
<h4>Create a new account</h4>
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
<!--ALL THESE INPUT BOXES ADJUST AUTOMATICALLY-->
<div class="form-group">
#Html.LabelFor(m => m.Address, new { #class = "col-md-5 control-label" })
<div class="col-md-7">
#Html.TextBoxFor(m => m.Address, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Address, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.City, new { #class = "col-md-5 control-label" })
<div class="col-md-7">
#Html.TextBoxFor(m => m.City, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.City, "", new { #class = "text-danger" })
</div>
</div>
<!--HERE IS THE DROPDOWLIST THAT NEEDS TO BE ADJUSTED DYNAMICALLY-->
<div class="form-group">
#Html.LabelFor(m => m.State, new { #class = "col-md-5 control-label" })
<div class="col-md-7 dropdownlist">
#Html.DropDownListFor(m => m.State, Steel_Tech.STATE.States, "--Select a State--", new { #class = "dropdownlist" })
#Html.ValidationMessageFor(m => m.State, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.Zip, new { #class = "col-md-5 control-label" })
<div class="col-md-7">
#Html.TextBoxFor(m => m.Zip, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Zip, "", new { #class = "text-danger" })
</div>
</div>
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-default" value="Create" />
</div>
}
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
Related
I have a problem adjusting my dropdowns to equally aligned to my textarea.
Html:
<!-- YEAR -->
<div class="col-md-6 col-md-push-1">
<div class="form-group">
#Html.LabelFor(model => model.Year, htmlAttributes: new { #class = "control-label col-md-6" })
#Html.DropDownListFor(model => model.Year, ViewBag.years as IEnumerable<SelectListItem>,
"-- Select Year --", new { #class = "form-control", #id = "cbYears" })
#Html.ValidationMessageFor(model => model.Year, "", new { #class = "text-danger" })
</div>
</div>
<!-- MONTH -->
<div class="col-md-6 col-md-push-1">
<div class="form-group">
#Html.LabelFor(model => model.Month, htmlAttributes: new { #class = "control-label col-md-12" })
#Html.DropDownListFor(model => model.Month, ViewBag.months as IEnumerable<SelectListItem>,
"-- Select Month --", new { #class = "form-control", #id = "cbMonth" })
#Html.ValidationMessageFor(model => model.Month, "", new { #class = "text-danger" })
</div>
</div>
<!-- GOOD -->
<div class="form-group">
<div class="col-md-4 col-md-push-1">
#Html.LabelFor(model => model.Good, htmlAttributes: new { #class = "control-label col-md-8" })
</div>
<div class="col-md-10 col-sm-push-1">
#Html.TextAreaFor(model => model.Good, new { maxlength = 5000, rows = "10", cols = "200", id = "txtGood" })
#*#Html.TextAreaFor(model => model.Good, new { maxlength = 5000, id = "txtGood" })*#
#Html.ValidationMessageFor(model => model.Good, "", new { #class = "text-danger" })
</div>
</div>
I just want to adjust my Month,Geography and Process dropdowns to push a little bit more to the right so it aligned to my textarea.
Preview
I think your .col-md classes have default bootstrap padding or margin.
So you can add the ".nopadding" class to a particular .col-md div to remove it.
.nopadding {
padding: 0 !important;
margin: 0 !important;
}
I use IDE to generate a view and controller from model automatically in MVC, however, when I try to change the size of textAreafor, I found the width has limitation , I cant make it more widely... here is my code, hope for some help
#model VeganCommunityApplication.Models.Article
#{
ViewBag.Title = "Create";
}
<h2>Create</h2>
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Article</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
.
.
.
<div class="form-group">
#Html.LabelFor(model => model.Content, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.TextAreaFor(model => model.Content,20,70,new {#style="width:400px;height:400px" })
#Html.ValidationMessageFor(model => model.Content, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
#Html.ActionLink("Back to List", "Index")
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
Change your textarea to this:
#Html.TextAreaFor(model => model.Content,20,70,new { #class = "col-md-12" })
This will make it 100% as wide as it's parent element.
For reference: Bootstrap grid system
You can change it like this:
#Html.TextAreaFor(model => model.Content, new { #class = "whatever-class", #cols = 40, #rows = 40 })
.whatever-class{
width:400px;
height:400px
}
I have a headache from this design.
How I can separate a little bit in inline form label and textbox which belongs to form-control class.
I've tried everything, and margin and align-text, but I didnt find solution
Here is a photo:
Here is the code:
<div class="container">
<div class="row">
<div class="span9">
<br />
<h2 style="margin-top:100px;text-align:center">
APPLY FOR INTERNSHIP PROGRAM
</h2>
</div>
<div class="col-md-4 col-sm-4 col-md-offset-4">
<br />
<div class="form-group">
#Html.LabelFor(model => model.Name, "Name", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.EditorFor(model => model.Name, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Name, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.Surname, "Surname", htmlAttributes: new { #class = "control-label col-md-2 col-md-2 col-sm-2" })
#Html.EditorFor(model => model.Surname, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Surname, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.Location, "Location", htmlAttributes: new { #class = "control-label col-md-2" })
#*#Html.DropDownList("LocationID", null, "--Choose location--", new { #class = "form-control" })*#
#Html.DropDownListFor(model => model.LocationID, ViewBag.LocationID as IEnumerable<SelectListItem>, "-----Select Category-----", new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Location, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.Mail, "E-mail", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.EditorFor(model => model.Mail, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Mail, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.Telephone, "Telephone number", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.EditorFor(model => model.Telephone, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Telephone, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.StartEduYear, "Entrance study year", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.DropDownListFor(model => model.StartEduYear, ViewBag.StartYearFaculty as IEnumerable<SelectListItem>, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.StartEduYear, "", new { #class = "text-danger" })
</div><br />
<div class="form-group">
#Html.LabelFor(model => model.EnglishLang.NameLang, "English level", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.DropDownList("EngID", null, "--Choose level--", new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.EngID, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.Faculty.FacultyName, "Faculty", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.DropDownListFor(model => model.FacultyID, ViewBag.FacultyID as IEnumerable<SelectListItem>, "--Select a faculty--", new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.FacultyID, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.AvgScore, "Average score", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.DropDownListFor(model => model.AvgScore, ViewBag.AverScore as IEnumerable<SelectListItem>, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.AvgScore, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.GradYear, "Graduation year", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.DropDownListFor(model => model.GradYear, ViewBag.GradYear as IEnumerable<SelectListItem>, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.GradYear, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.WExp, "Work Experience", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.TextAreaFor(model => model.WExp, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.WExp, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.Interests, "Interests", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.TextAreaFor(model => model.Interests, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Interests, "", new { #class = "text-danger" })
</div>
<span>Did you have any additional trainings?</span>
<label for="chkYes">
<input type="radio" id="chkYes" name="chkPassPort" onclick=" ShowHideDiv() " />Yes
</label>
<label for="chkNo">
<input type="radio" id="chkNo" name="chkPassPort" onclick=" ShowHideDiv() " />No
</label>
<div class="form-group" id="dvPassport" style="display: none">
#Html.LabelFor(model => model.Trainings, "Trainings", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.TextAreaFor(model => model.Trainings, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Trainings, "", new { #class = "text-danger" })
</div>
<p></p>
<span>Did you have any projects recently?</span>
<label for="chkYes">
<input type="radio" id="chkYes1" name="chkPassPort1" onclick=" ShowHideDiv() " />Yes
</label>
<label for="chkNo">
<input type="radio" id="chkNo1" name="chkPassPort1" onclick=" ShowHideDiv() " />No
</label>
<div class="form-group" id="dvExample" style="display: none">
#Html.LabelFor(model => model.Projects, "Projects", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.TextAreaFor(model => model.Projects, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Projects, "", new { #class = "text-danger" })
</div>
<p></p>
<span>Have you been in some students organization?</span>
<label for="chkYes">
<input type="radio" id="chkYes2" name="chkPassPort2" onclick=" ShowHideDiv() " />Yes
</label>
<label for="chkNo">
<input type="radio" id="chkNo2" name="chkPassPort2" onclick=" ShowHideDiv() " />No
</label>
<div class="form-group" id="dvExample1" style="display: none">
#Html.LabelFor(model => model.StudOrg, "Organizations", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.TextAreaFor(model => model.StudOrg, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.StudOrg, "", new { #class = "text-danger" })
</div>
<p></p>
<input type="submit" value="Apply" class="btn btn-default" style="text-align: center" />
</div>
#*<div class="form-group">
sdsdsdsd
<div class="g-recaptcha" data-sitekey="6LccVRcTAAAAADLo_LxSj4mQzt9jLrgbo5L9wZ-J"></div>
<div>sdsdsds11
#if (TempData["recaptcha"] != null)
{
<p>#TempData["recaptcha"]</p>
}
</div>
</div>*#
#*<div class="col-md-offset-2 col-md-10">
<div class="form-group">1231
#Html.Recaptcha()
</div>
</div>*#
</div>
</div>
I think you need to take another look at Bootstrap documentation. If you're using Bootstrap 3.x, you should not be using span* (that belong to Bootstrap 2.x). span* have been replaced with col-md-*.
You can refer to this migration guide.
Also, you should place all of your .form-group elements inside a .form-horizontal container.
You're simply not giving the elements enough room. Your form is restricted to 4 columns and then your label is restricted to 2 columns. Essentially, the form is 4/12 of the total available width, then your label is 2/12 of that, which means overall your label is only 1/18 of the total available width. Just give it some more breathing room. Perhaps make your form col-md-6 or col-md-8 and your label something like col-md-3. Or if you want to stick with col-md-4 for the whole form, increase your label to something like col-md-4.
I have a standard login page on mvc 4 which is functioning fine but my html knowledge is very weak and I need a quick answer to tidying up the form after I installed twitter bootstrap, the username and password labels are stuck on the same line within the form, can someone please recommend a quick fix to tidying up my code, Thanks
#model MvcApplication2.Models.login_details
#{
ViewBag.Title = "Log in";
}
<br /><br /><br />
<h2>#ViewBag.Title.</h2>
<div class="row">
<div class="col-md-8">
<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, "", new { #class = "text-danger" })
<div class="col-md-10">
#Html.LabelFor(m => m.username, new { #class = "col-md-2 control-label"})
<div class="col-md-10">
#Html.TextBoxFor(m => m.username, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.username, "", 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.PasswordFor(m => m.password, new { #class = "form-control"})
#Html.ValidationMessageFor(m => m.password, "", new { #class = "text-danger"})
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default" />
</div>
</div>
}
</section>
</div>
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
Easy :)
Just change the LabelFor's class from col-md-2 to col-md-3 then add another item, text-left.
So your labels should look like:
#Html.LabelFor(m => m.Email, new { #class = "col-md-3 control-label text-left" })
#Html.LabelFor(m => m.Password, new { #class = "col-md-3 control-label text-left" })
Then goto Site.css (~/Content/site.css) and add the following to the bottom:
.form-horizontal .control-label.text-left{
text-align: left;
}
I would recomend though that you learn HTML/JS/Bootstrap as if your making websites ever professionally you almost always will have to be competent with basic HTML/JS/Bootstrap(sometimes)
I have two projects in mvc .
in one of them i use this code :
#Html.LabelFor(model => model.Subject, new { #class = "control-label col-lg-2" })
And it works correctly because the project has an extension method for labelfor as you can see here :
public static System.Web.Mvc.MvcHtmlString LabelFor<TModel, TValue>(this System.Web.Mvc.HtmlHelper<TModel> html, System.Linq.Expressions.Expression<Func<TModel,TValue>> expression, object htmlAttributes)
But in the other project when i use the above code i mean :
#Html.LabelFor(model => model.Name, new { #class = "control-label col-lg-2" })
I got this error :
CS1928: 'System.Web.Mvc.HtmlHelper<DomainClass.Task>' does not contain a definition for 'LabelFor' and the best extension method overload 'System.Web.Mvc.Html.LabelExtensions.LabelFor<TModel,TValue>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TValue>>, string)' has some invalid arguments
In the object browser i couldn't find the above extension that the other project has.as you can see here :
where is the problem?should i change the mvc version ?
here is the view code :
#model DomainClass.Task
#using System.Web.Mvc.Html;
#{
ViewBag.Title = "Create";
Layout = "~/Areas/Admin/Views/Shared/_LayoutPage.cshtml";
}
#using (Html.BeginForm("Create", "Task", FormMethod.Post, new { id = "form", enctype = "multipart/form-data" ,#class = "cmxform form-horizontal tasi-form" }))
{
<div class="row">
<div class="col-lg-12">
<section class="panel panel-default">
<div class="panel-heading" style="font-weight: bold">ثبت نمایشگاه </div>
<div class="panel-body">
<div class=" form">
<div class="form-group">
#Html.LabelFor(model => model.Name, new { #class = "control-label col-lg-2" })
<div class="col-lg-10">
#Html.TextBoxFor(model => model.Name, new { #class = "form-control myfont" })
#Html.ValidationMessageFor(i => i.Name, "", new { #class = "validation" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.StartDate, new { #class = "control-label col-lg-2" })
<div class="col-lg-10">
#Html.TextBoxFor(model => model.StartDate, new { #class = "form-control myfont" })
#Html.ValidationMessageFor(i => i.StartDate, "", new { #class = "validation" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.FinishDate, new { #class = "control-label col-lg-2" })
<div class="col-lg-10">
#Html.TextBoxFor(model => model.FinishDate, new { #class = "form-control myfont" })
#Html.ValidationMessageFor(i => i.FinishDate, "", new { #class = "validation" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Duration, new { #class = "control-label col-lg-2" })
<div class="col-lg-10">
#Html.TextBoxFor(model => model.Duration, new { #class = "form-control myfont" })
#Html.ValidationMessageFor(i => i.Duration, "", new { #class = "validation" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Importance, new { #class = "control-label col-lg-2" })
<div class="col-lg-10">
#Html.TextAreaFor(model => model.Importance, new { #class = "form-control myfont" })
#Html.ValidationMessageFor(i => i.Importance, "", new { #class = "validation" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.DateOfSubmit, new { #class = "control-label col-lg-2" })
<div class="col-lg-10">
#Html.TextAreaFor(model => model.DateOfSubmit, new { #class = "form-control myfont" })
#Html.ValidationMessageFor(i => i.DateOfSubmit, "", new { #class = "validation" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Type, new { #class = "control-label col-lg-2" })
<div class="col-lg-10">
#Html.TextAreaFor(model => model.Type, new { #class = "form-control myfont" })
#Html.ValidationMessageFor(i => i.Type, "", new { #class = "validation" })
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button class="btn btn-success" type="submit">ثبت اطلاعات</button>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
}
Best regards
I finally remove my asp.mvc from nuget and install it again .and it works fine.