I have the following html.beginform. I want to make all of editorfor statement in foreach. Can someone help me? I use a ViewData.ModelMetadata.Properties, but the Save is out of function.
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Test mit DbFunction</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.ANLAGEID, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.ANLAGEID, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.ANLAGEID, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.ANLAGENAME, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.ANLAGENAME, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.ANLAGENAME, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.ANLAGEART, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.ANLAGEART, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.ANLAGEART, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.ANLAGENUMMER, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.ANLAGENUMMER, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.ANLAGENUMMER, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Speichern" class="btn btn-default" />
</div>
I use too foreach loop, but this is not working. It is possible to use a #for loop to solve me problem? If yes, can anyone explain how. Hier ist the foreach
#foreach (var property in ViewData.ModelMetadata.Properties)
{
<div class="editor-line">
<label>#(property.DisplayName ?? property.PropertyName)</label>
#Html.Editor(property.PropertyName)
</div>
}
#foreach (var item in Model) {
<td>
#Html.DisplayFor(modelItem => item.EvaluatedRole)
</td>
<td>
#Html.DisplayFor(modelItem => item.QuestionName)
</td>
<td>
#Html.DisplayFor(modelItem => item.EvaluatedBy)
</td>
<td>
#Html.DisplayFor(modelItem => item.Description)
</td>
<td>
#Html.DisplayFor(modelItem => item.Weightage)
</td>
<td>
#Html.DisplayFor(modelItem => item.AnswerName)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { questionid=item.QuestionID })
</td>
<td>
<button class="btn-link btnDelete" #*onclick="ConfirmationAlert()"*#>Delete</button>
#Html.ActionLink("Delete", "Delete", new { questionid = item.QuestionID }, new { id="lnkBtn" ,style="Display:none"})
</td>
</tr>
}
Related
I am having a great deal of trouble trying to get things to line up correctly and be presented in the same row. I am using MVC 5 razor pages with HTML and Bootstrap.css file. I have been fiddling with it for a few days now making limited progress from where I began. I will post anything else that is needed in order to help me figure this out - there are more divisions in the table - but I wanted to be as brief as possible.
Here is the screen shots of what I do not want and what I am trying to achieve:
Here is my markup code:
<table style="width: 1562px; height: 836px;" cellpadding="1"; cellspacing="0"; border="1"; >
<caption class = "control-label col-md-2", style = "display:inline; white-space:nowrap">
#Html.DisplayFor(model => model.Title)<br>
</caption>
<tbody>
<tr>
#*SECTION TITLE MODIFIED .. CATEGORY*#
<td colspan="1" rowspan="4" style="vertical-align: middle; width: 244px; margin-left:4px" class="form-horizontal" >
<br>
<ul style="color: blue; list-style-type: none; list-style-image: none; list-style-position: outside; width: 260px;" class="form-horizontal">
<li>
#Html.LabelFor(model => model.Title, htmlAttributes: new { #class = "control-label col-md-2", style = "display:inline; white-space:nowrap" })
#Html.EditorFor(model => model.Title, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Title, "", new { #class = "text-danger" })
</li>
<li>
#Html.LabelFor(model => model.PublishDate, htmlAttributes: new { #class = "control-label col-md-2", style = "display:inline; white-space:nowrap" })
#Html.EditorFor(model => model.PublishDate, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.PublishDate, "", new { #class = "text-danger" })
</li>
<li style="display:inline-block; width:auto">
<div class="form-horizontal">
#Html.LabelFor(model => model.ModifiedDate, htmlAttributes: new { #class = "control-label col-md-2", style = "display:inline; white-space:nowrap" })
<div style="width:50%">
#Html.EditorFor(model => model.ModifiedDate, new { htmlAttributes = new { #class = "form-control" , style= "width:50%" } })
#Html.ValidationMessageFor(model => model.ModifiedDate, "", new { #class = "text-danger", style = "width:50%" })
</div>
</div>
</li>
<li> <p style="display:inline-block">
<div class="form-horizontal" id="isActive">
#Html.LabelFor(model => model.IsActive, htmlAttributes: new { #class = "control-label col-md-1" })
</div>
<div class="checkbox" style="align-items:flex-end;">
#Html.EditorFor(model => model.IsActive)
#Html.ValidationMessageFor(model => model.IsActive, "", new { #class = "text-danger" })
</div>
</p>
<br style="line-height:20px" />
</li>
<li> <p>
<div class="form-horizontal" id="ddlCategoryGroup" style="display:inline-block;white-space:nowrap;">
#Html.LabelFor(model => model.CategoryId, "Category", htmlAttributes: new { #class = "control-label col-md-2" })
</div>
<br style="line-height:25px;" />
<p>
<div class="col-md-10" id="ddlCategory">
#Html.DropDownList("CategoryId", null, htmlAttributes:
new { #class = "form-control", style = "font-family:'Franklin Gothic Medium', 'ArialNarrow', Arial, sans-serif; font-size:1.2EM; width:auto; display:inline; white-space:nowrap" })
#Html.ValidationMessageFor(model => model.CategoryId, "", new { #class = "text-danger" })
</div>
</p><br/>
<p style="display:inline-block">
<div>
#Ajax.ActionLink("New", "Create", "Category", Model.Category,
new AjaxOptions { UpdateTargetId = "ddlCategory", InsertionMode = InsertionMode.Replace },
new { htmlAttributes = new { #class = "control-label col-md-2" } }) |
#Ajax.ActionLink("Edit", "Edit", "Category", Model.Category,
new AjaxOptions { UpdateTargetId = "ddlCategory", InsertionMode = InsertionMode.Replace },
new { htmlAttributes = new { #class = "control-label col-md-2" } }) |
#Html.ActionLink("Delete", "Delete", new { id = #Model.CategoryId }, new { htmlAttributes = new { #class = "control-label col-md-2" } })
</div>
</p>
</p>
</li>
</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
</tbody>
</table>
For the "published on" and "last modified" input fields you can try using the flex classes in bootstrap.
<div class="d-flex">
<input type="text" />
<button><i class="fa fa-calendar"></i></button>
</div>
1.bootstrap doc flex
2.Here is a cheat sheet for flex boxes
Instead of using tables and List elements for designing I would prefer to use bootstrap classes and div elements as they will give you more control on what you are doing. Take a look at the following code.
First make a parent div with class form-horizontal then for each input make a div with class form-group
<div class="form-horizontal">
<h4>Write a Suitable title for your Form</h4>
<hr />
<div class="form-group"> #*Create this div for each form input element*#
#Html.LabelFor(model => model.Title, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-6"> #*Based on your requirement you can change the col-md-3 value any where from 1 to 10*#
#Html.EditorFor(model => model.Title, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Title, "", new { #class = "text-danger" })
</div>
</div>
</div>
So as you noticed
for complete form we are having a div parent class form-horizontal
for each input element we will have a form-group div class
within each form-group we will have 2 elements label and a div with class col-md-6(or whatever length you prefer) containing the main input element(textbox, dropdown, checkbox etc)
So stop using li Elements and replace them with div with class form-group will sort many issues for you.
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")
}
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 an issue with the layout of some html elements. I have a form which i am changing into a tabbed display in order to split it up and make it more usable. The existing form looks like this:
However, when i use the same code inside of a tab, the result is as below:
As i stated, the code for it is exactly the same as below:
<div class="col-md-12" style="display:block;">
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Receiver, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CommunicationModel.Communication.Receiver, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.Receiver, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Department.Name, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DisplayFor(model => model.CommunicationModel.Communication.Department.Name)
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.DepartmentId, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.DateOpened, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
<span id="custSpan" style="font-size:14px;">
#Html.DisplayFor(model => model.CommunicationModel.Communication.DateOpened)
#Html.HiddenFor(model => model.CommunicationModel.Communication.DateOpened)
</span>
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Method, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EnumDropDownListFor(model => model.CommunicationModel.Communication.Method, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.Method, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Product, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CommunicationModel.Communication.Product, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.Product, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.PartNo, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CommunicationModel.Communication.PartNo, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.PartNo, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Description, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CommunicationModel.Communication.Description, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.Description, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Severity.Description, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DropDownListFor(model => model.CommunicationModel.Communication.SeverityId, new SelectList(Model.AllSeverities, "Id", "DisplayName"), new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
</div>
It appears to be certain elements affecting the layout. So far i have noticed it on both Html.DisplayFor() and Html.EnumDropDownListFor() (an extension of standard DropDownListFor(). It appears to indent the elements on the next line for some reason.
Can anybody help with this?
Many thanks :)
Try this,
<div class="col-md-12" style="display:block;">
<div class="form-horizontal">
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Receiver, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CommunicationModel.Communication.Receiver, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.Receiver, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Department.Name, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DisplayFor(model => model.CommunicationModel.Communication.Department.Name)
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.DepartmentId, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.DateOpened, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
<span id="custSpan" style="font-size:14px;">
#Html.DisplayFor(model => model.CommunicationModel.Communication.DateOpened)
#Html.HiddenFor(model => model.CommunicationModel.Communication.DateOpened)
</span>
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Method, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EnumDropDownListFor(model => model.CommunicationModel.Communication.Method, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.Method, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Product, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CommunicationModel.Communication.Product, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.Product, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.PartNo, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CommunicationModel.Communication.PartNo, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.PartNo, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Description, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.CommunicationModel.Communication.Description, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.CommunicationModel.Communication.Description, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.CommunicationModel.Communication.Severity.Description, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DropDownListFor(model => model.CommunicationModel.Communication.SeverityId, new SelectList(Model.AllSeverities, "Id", "DisplayName"), new { #class = "form-control" })
</div>
</div>
</div>
</div>
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.