Can';t在MVC表单中添加CSS样式
我开发了MVC项目,我想设计我的项目,但它不能正常工作;我不能设计我的表格从控件、按钮和输入区域如何在项目中执行?我想要一些帮助 我的代码Can';t在MVC表单中添加CSS样式,css,asp.net-mvc,Css,Asp.net Mvc,我开发了MVC项目,我想设计我的项目,但它不能正常工作;我不能设计我的表格从控件、按钮和输入区域如何在项目中执行?我想要一些帮助 我的代码 @model ContosoUniversity.Models.Student @{ ViewBag.Title = "Create"; } <h2>Create</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div cl
@model ContosoUniversity.Models.Student
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Student</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control " } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FirstMidName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstMidName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FirstMidName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EnrollmentDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EnrollmentDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EnrollmentDate, "", 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")
}
@model ContosoUniversity.Models.Student
@{
ViewBag.Title=“创建”;
}
创造
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
学生
@Html.ValidationSummary(true,“,new{@class=“text danger”})
@LabelFor(model=>model.LastName,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.LastName,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.LastName,“,new{@class=“text danger”})
@LabelFor(model=>model.FirstMidName,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.FirstMidName,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.FirstMidName,“,new{@class=“text danger”})
@LabelFor(model=>model.EnrollmentDate,htmlAttributes:new{@class=“control label col-md-2”})
@EditorFor(model=>model.EnrollmentDate,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.EnrollmentDate,“,new{@class=“text danger”})
}
@ActionLink(“返回列表”、“索引”)
@节脚本{
@Scripts.Render(“~/bundles/jqueryval”)
}
您必须执行以下步骤:
- 使用您想要应用的样式规则创建CSS文件(您将很容易找到许多CSS文件创建教程)
- 将创建的CSS文件添加到样式包中。要执行此操作,请转到“BundleConfig.cs”文件,并添加以下行(用实值替换bundle名称和CSS文件路径): 添加(新样式包(“~/nameofbundle”)。包括(“~/Content/YourCssFile.css”)
- 将对已创建捆绑包的引用添加到cshtml文件中(在文件顶部的标记之间): @Styles.Render(“~/nameofbundle”)
如果我的答案不够清楚,请告诉我。您必须执行以下步骤:
- 使用您想要应用的样式规则创建CSS文件(您将很容易找到许多CSS文件创建教程)
- 将创建的CSS文件添加到样式包中。要执行此操作,请转到“BundleConfig.cs”文件,并添加以下行(用实值替换bundle名称和CSS文件路径): 添加(新样式包(“~/nameofbundle”)。包括(“~/Content/YourCssFile.css”)
- 将对已创建捆绑包的引用添加到cshtml文件中(在文件顶部的标记之间): @Styles.Render(“~/nameofbundle”)
如果我的答案不够清楚,请告诉我。您可以通过多种方式添加css。最好的方法是创建自己的css文件,并将其绑定到bundle。或者您可以将其放置在_Layout.cshtml head部分:
<style>
.custom-class{
border:1px solid red;
}
</style>
.定制类{
边框:1px纯红;
}
那么使用它就相当简单了:
<div class="form-group custom-class">
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control " } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
</div>
@LabelFor(model=>model.LastName,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.LastName,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.LastName,“,new{@class=“text danger”})
希望这会有所帮助:)您可以通过多种方式添加css。最好的方法是创建自己的css文件,并将其绑定到bundle。或者您可以将其放置在_Layout.cshtml head部分:
<style>
.custom-class{
border:1px solid red;
}
</style>
.定制类{
边框:1px纯红;
}
那么使用它就相当简单了:
<div class="form-group custom-class">
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control " } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
</div>
@LabelFor(model=>model.LastName,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.LastName,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.LastName,“,new{@class=“text danger”})
希望这会有所帮助:)我不知道如何使用它?你找过在线教程吗?请给我一个教程链接,更好,谢谢:)你可以看看这些我不知道如何使用它?你找过在线教程吗?请给我一个教程链接,更好,谢谢:)你可以看看这些谢谢你的帮助。谢谢你的帮助。