bootstrap form alignment with multiple controls - twitter-bootstrap-3

Hello all I am having my design as follows in my html
#model PPM.Models.ProjectModel
<div class="panel-heading panel-head">Create New Project</div>
<br />
<div class="container">
<div class="form-horizontal">
#using (Ajax.BeginForm("Invite", "Invite", null, new AjaxOptions() { HttpMethod = "post", LoadingElementId = "divLoading", OnSuccess = "getresult" }, null))
{
<div class="form-group">
<label for="ProjectName" class="col-sm-4">Project Name</label>
#Html.EditorFor(model => model.ProjectName, "", new { htmlAttributes = new { #class = "form-control", #placeholder = "Project Name" } })
#Html.ValidationMessageFor(model => model.ProjectName, "", new { #class = "text-danger" })
</div>
<div class="form-group">
<label for="ManagerId" class="col-sm-4">Project Manager</label>
#Html.DropDownListFor(Model => Model.ManagerId, Model.ManagerList, "--SELECT--", new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.ManagerId, "", new { #class = "text-danger" })
</div>
<div class="control-group">
<label for="Duration">Duration </label>
#Html.EditorFor(model => model.Duration, "", new { htmlAttributes = new { #class = "form-control", #placeholder = "Duration" } })
#Html.ValidationMessageFor(model => model.Duration, "", new { #class = "text-danger" })
#Html.DropDownListFor(Model => Model.DurationId, Model.DurationTypes, "--SELECT--", new { #class = "form-control input-xs" })
#Html.ValidationMessageFor(model => model.DurationId, "", new { #class = "text-danger" })
</div>
<div class="form-group">
<label for="NoOfResources" class="col-sm-4">No Of Resources</label>
#Html.EditorFor(model => model.NoOfResourses, "", new { htmlAttributes = new { #class = "form-control", #placeholder = "Number of resources" } })
</div>
<div class="form-group">
<label for="StartDate" class="col-sm-4">Start Date</label>
#Html.EditorFor(model => model.StartDate, "", new { htmlAttributes = new { #class = "form-control", #placeholder = "Number of resources" } })
</div>
<div class="form-group">
<label for="EndDate" class="col-sm-4">End Date</label>
#Html.EditorFor(model => model.EndDate, "", new { htmlAttributes = new { #class = "form-control", #placeholder = "Number of resources" } })
</div>
}
</div>
</div>
I am getting form as expected but I am unable to align one control inline. can some one help me. I would like to see them in one line

It looks like you aren't using columns for the 'Duration' label so what you have is:
<label for="Duration">Duration </label>
When it should be:
<label for="Duration" class="col-sm-4">Duration </label>
like the rest of your labels.

Related

How to add more fields to contact us page in nop commerce?

How can I add more fields to "contact us" form in nop commerce? I'm new to nop commerce.
I added a field to ContactUs.cshtml but nothing is showing on my side when I load the form.
I have added the Postal Address but it doesn't show
<div class="fieldset">
<div class="form-fields">
<div class="inputs">
#Html.LabelFor(model => model.FullName)
#Html.TextBoxFor(model => model.FullName, new { #class = "fullname", placeholder = T("ContactUs.FullName.Hint") })
#Html.RequiredHint()
#Html.ValidationMessageFor(model => model.FullName)
</div>
<div class="inputs">
#Html.LabelFor(model => model.PostalAddress)
#Html.TextAreaFor(model => model.PostalAddress, new { #class = "postaladdress", placeholder = T("ContactUs.PostalAddress.Hint") })
#Html.RequiredHint()
#Html.ValidationMessageFor(model => model.PostalAddress)
</div>
<div class="inputs">
#Html.LabelFor(model => model.Email)
#Html.TextBoxFor(model => model.Email, new { #class = "email", placeholder = T("ContactUs.Email.Hint") })
#Html.RequiredHint()
#Html.ValidationMessageFor(model => model.Email)
</div>
#if (Model.SubjectEnabled)
{
<div class="inputs">
#Html.LabelFor(model => model.Subject)
#Html.TextBoxFor(model => model.Subject, new { #class = "subject", placeholder = T("ContactUs.Subject.Hint") })
#Html.RequiredHint()
#Html.ValidationMessageFor(model => model.Subject)
</div>
}
<div class="inputs">
#Html.LabelFor(model => model.Enquiry)
#Html.TextAreaFor(model => model.Enquiry, new { #class = "enquiry", placeholder = T("ContactUs.Enquiry.Hint") })
#Html.RequiredHint()
#Html.ValidationMessageFor(model => model.Enquiry)
</div>
#if (Model.DisplayCaptcha)
{
<div class="captcha-box">
#Html.Raw(Html.GenerateCaptcha())
</div>
}
</div>
</div>
<div class="buttons">
<input type="submit" name="send-email" class="button-1 contact-us-button" value="#T("ContactUs.Button")" />
</div>
}
}
If you are using a theme you should edit the view under the folder "Themes>NameOfYourTheme>WhatEverView" and not the one directly under the "views" folder.
Check if that is the reason.

In MVC While adding form is doing postback fine. But When Editing same from Submit button is not working. Its Not hitting Controller Method

This is my part of code . Here i can add and submit the values. But while editing submit is not working. Can anyone help me on this. What can be the Issue over here.
#using (Html.BeginForm("LenseAdd", "Stock", FormMethod.Post, new { #class = "form-horizontal form-bordered" }))
{
#Html.AntiForgeryToken()
#Html.HiddenFor(m => m.LenseId)
#Html.HiddenFor(m => m.MaterialId)
<div class="form-group">
<label class="control-label col-lg-3 col-sm-3">Lense Code<span class="text-danger">*</span></label>
<div class="col-lg-6 col-sm-8">
<div class="input-group">
#*<input type="text" class="form-control" />*#
#Html.TextBoxFor(m => m.LenseCode, new { #class = "form-control", #placeholder = "Lense Code", #id = "LenseCode" })
<span class="input-group-addon"><span class="fa fa-money"></span></span>
</div>
#Html.ValidationMessageFor(m => m.LenseCode, null, new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3 col-sm-3">BrandName<span class="text-danger">*</span></label>
<div class="col-lg-6 col-sm-8">
<div class="input-group">
#Html.DropDownListFor(m => m.BrandId, (IEnumerable<SelectListItem>)ViewBag.BrandList, "--select--", new { #class = "form-control", #id = "ddlbranchId" })
<span class="input-group-addon"><span class="fa fa-money"></span></span>
</div>
#*#Html.ValidationMessageFor(m => m.SalaryTo, null, new { #class = "text-danger" })*#
</div>
</div>
<div class="form-group">
#if (Model != null)
{
if (Model.CategoryList != null)
{
<label class="control-label col-lg-3 col-sm-3">Material</label>
foreach (var item in Model.CategoryList)
{
if (item.CategoryName == "MATERIAL")
{
<div class="col-lg-1 col-sm-3">
<div class="c-form__group -radio -inline">
<label class="c-form__control-text radio_heading">
<label>#item.Name</label>
#if (Model.MaterialId == item.ID)
{
#Html.RadioButtonFor(m => m.MaterialId, true, new { #checked = "checked", #class = "MATERIAL", #id = "MATERIAL_"+item.ID.ToString() })
}
else
{
#Html.RadioButtonFor(m => m.MaterialId, false, new { #class = "MATERIAL", #id = "MATERIAL_" + item.ID.ToString() })
}
<div class="-indicator"></div>
</label>
</div>
</div>
}
}
}
}
</div>
<div class="panel-footer">
<div class="row">
<div class="col-md-10 text-right">
<div class="btn-group">
<button type="submit" class="btn btn-custom fa fa-save -blue" >Save & New</button>
<button type="submit" class="btn btn-custom fa fa-save -skyblue" id="btn_submit">Save</button>
Cancel
</div>
</div>
</div>
</div>
}
I didn't copy the full cshtml page. here if you see any div mismatching please ignore. Any help will be appreciated.

How to fetch model value to api controller from ajax call

I am trying to add User Type details to database. When Passing through ajax to Web API ... model value is passing as null ... I need Model value to be passed as Parameter .. Can an one Help me on this
#model ConstructionModels.UserTypeModel
#using Newtonsoft.Json
#{
// Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>UserTypeModel</h4>
<hr />
<div class="form-group">
#Html.LabelFor(model => model.User_Type, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.TextBoxFor(model => model.User_Type, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" id="btnSave" class="btn btn-default" />
</div>
</div>
</div>
}
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script>
var baseUrl= '#System.Configuration.ConfigurationManager.AppSettings["ApiUrl"]';
$("#btnSave").click(function () {
var data1 = #Html.Raw(JsonConvert.SerializeObject(this.Model));
console.log(data1);
$.ajax({
url: baseUrl + 'Usertype/Save',
type: 'post',
data: data1,
dataType: 'json',
success: function () {
alert("Saved");
},
error: function (error) {
alert("Error While Saving");
}
})
})
</script>

MVC5 form with Bootstrap

When I restore down my window, my form looks good:
But if I span my window it doesnt look very well:
my view code is:
#using System.Collections
#using System.Collections.Concurrent
#using System.Data.SqlTypes
#using DataAccess
#using Recaptcha.Web.Mvc
#using Recaptcha.Web;
#using Recaptcha.Web.Mvc;
#model DataAccess.Employee
#{
ViewBag.Title = "Create";
}
#{ Layout = "/views/shared/_EmployeeLayout.cshtml";
}
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="container">
<h2>Please, provide some information.</h2>
<div class="row">
<div class="col-md-8">
<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" })
#Html.LabelFor(model => model.Surname, "Surname", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.EditorFor(model => model.Surname, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Surname, "", new { #class = "text-danger" })
#Html.LabelFor(model => model.Location, "Location", htmlAttributes: new { #class = "control-label col-md-2" })
#Html.DropDownList("LocationID", null, "--Please pick one--", new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Location, "", new { #class = "text-danger" })
#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" })
#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" })
#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" })
#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" })
#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>, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.FacultyID, "", new { #class = "text-danger" })
#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" })
#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" })
#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" })
#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" })
<p></p>
<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" })
<div class="col-md-10">
#Html.TextAreaFor(model => model.Trainings, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Trainings, "", new { #class = "text-danger" })
</div>
</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" })
<div class="col-md-10">
#Html.TextAreaFor(model => model.Projects, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Projects, "", new { #class = "text-danger" })
</div>
</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" })
<div class="col-md-10">
#Html.TextAreaFor(model => model.StudOrg, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.StudOrg, "", new { #class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="g-recaptcha" data-sitekey="6LccVRcTAAAAADLo_LxSj4mQzt9jLrgbo5L9wZ-J"></div>
<div>
#if (TempData["recaptcha"] != null)
{
<p>#TempData["recaptcha"]</p>
}
</div>
</div>
<br />
<br />
<div class="col-md-offset-2 col-md-10">
<b></b>
<div class="form-group">
#Html.Recaptcha()
</div>
<br />
<br />
<br />
<br />
<input type="submit" value="Apply" class="btn btn-default" style="text-align: center" />
</div>
</div>
<p></p>
</div>
</div>
}
<script type="text/javascript">
function ShowHideDiv() {
var chkYes = document.getElementById("chkYes");
var chkYes1 = document.getElementById("chkYes1");
var chkYes2 = document.getElementById("chkYes2");
var dvPassport = document.getElementById("dvPassport");
var dvExample = document.getElementById("dvExample");
var dvExample1 = document.getElementById("dvExample1");
dvPassport.style.display = chkYes.checked ? "block" : "none";
dvExample.style.display = chkYes1.checked ? "block" : "none";
dvExample1.style.display = chkYes2.checked ? "block" : "none";
}
</script>
I also had each field into separate , and main field was in column-10, but even then my fields was over collapsing each other..
put each row like this seperatly
<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>

Captcha is not loading While adding Screen restriction

I am developing my project in MVC. In registration page i am using captcha control. It is working Fine. But my problem is i am adding screen restriction to some of my pages. While adding screen restriction captcha is not getting loaded.
can anyone please help me?
I have added the screen restriction code below
public class ScreenRestriction : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var routeData = filterContext.HttpContext.Request.RequestContext.RouteData;
string currentAction = routeData.GetRequiredString("action");
string currentController = routeData.GetRequiredString("controller");
string currentArea = routeData.Values["area"] as string;
var request = filterContext.HttpContext.Request;
var response = filterContext.HttpContext.Response;
var session = filterContext.HttpContext.Session;
if ((currentAction != "Login" && currentAction != "Create" && currentAction != "GetUser" && currentAction != "Index" ) == true)
{
if (session["UserID"] == null)
{
if (request.IsAjaxRequest())
{
response.StatusCode = 590;
}
else
{
var url = new UrlHelper(filterContext.HttpContext.Request.RequestContext);
response.Redirect(url.Action("Login", "CU"));
}
filterContext.Result = new EmptyResult();
}
else
{
if (!filterContext.HttpContext.Request.IsAjaxRequest())
{
}
}
}
base.OnActionExecuting(filterContext);
}
Screen restriction in Filters
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new ScreenRestriction());
}
}
I have added the registration page code below
View--
#model SYTMain.Models.tblUser
#using CaptchaMvc.HtmlHelpers
#using CaptchaMvc;
#{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout_for_registration.cshtml";
}
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<fieldset>
<legend>tblUser</legend>
<div class="editor-label">
#Html.LabelFor(model => model.FirstName)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.FirstName)
#Html.ValidationMessageFor(model => model.FirstName)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.MiddleName)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.MiddleName)
#Html.ValidationMessageFor(model => model.MiddleName)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.LastName)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.LastName)
#Html.ValidationMessageFor(model => model.LastName)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.EmailID)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.EmailID)
#Html.ValidationMessageFor(model => model.EmailID)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.Password)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.Password)
#Html.ValidationMessageFor(model => model.Password)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.AddressId, "Address1")
</div>
<div class="editor-field">
#Html.EditorFor(model => model.tblAddress.Address1)
#Html.ValidationMessageFor(model => model.tblAddress.Address1)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.AddressId, "Address2")
</div>
<div class="editor-field">
#Html.EditorFor(model => model.tblAddress.Address2)
#Html.ValidationMessageFor(model => model.tblAddress.Address2)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.MobileNumber)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.MobileNumber)
#Html.ValidationMessageFor(model => model.MobileNumber)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.WorkNumber)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.WorkNumber)
#Html.ValidationMessageFor(model => model.WorkNumber)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.HomeNumber)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.HomeNumber)
#Html.ValidationMessageFor(model => model.HomeNumber)
</div>
#Html.Captcha(3)
<br />
<p class="Error"> #ViewBag.ErrMessage </p>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
Controller
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(tblUser tbluser)
{
string val = System.Configuration.ConfigurationManager.AppSettings["CUTypeId"];
int code = Convert.ToInt32(val);
Session["Emailid"] = tbluser.EmailID.Trim();
if (ModelState.IsValid && this.IsCaptchaValid("Captcha Not Valid") )
{
EmailManager.SendConfirmationEmailName(tbluser.EmailID, tbluser.FirstName);
tbluser.UserTypeId = code;
db.tblUsers.Add(tbluser);
db.SaveChanges();
return RedirectToAction("Login", new { Email = tbluser.EmailID });
}
ViewBag.BusinessCategoryId = new SelectList(db.tblBusinessCategories, "BusinessID", "BusinessName", tbluser.BusinessCategoryId);
ViewBag.UserTypeId = new SelectList(db.tblUserTypes, "UserTypeID", "UserType", tbluser.UserTypeId);
ViewBag.AddressId = new SelectList(db.tblAddresses, "AddressID", "Address1", tbluser.AddressId);
ViewBag.ErrMessage = "Error: Captcha not valid";
return View(tbluser);
}