在MVC视图中使用<script></script>
和<style></style>
标记是一种好习惯吗?例如,请在随附的简单视图示例中考虑以下代码段。
function myFunction(){
//在这做点什么
返回false;
}
.myCssClass {color:red}
@model JavaScript_CSS_Test.Models.Employee
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Employee</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<p>
<input type="submit" id="btnSubmit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">
function myFunction() {
//do something here
return false;
}
</script>
<style type="text/css">
.myCssClass{ color:red }
</style>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}