我能在同一个cshtml页面中插入HTML代码和Razor代码吗?
我能在同一个cshtml页面中插入HTML代码和Razor代码吗?
我可以在同一页中使用这个Razor CSHTML代码插入HTML设计/代码吗?
@model project_final.Models.Bike
@{
ViewBag.Title = "Create";
}
Create
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
}
@Html.ActionLink("Back to List", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
在cshtml页面中可以插入HTML代码和Razor代码,但需要注意Razor引擎中需要使用@符号的代码,以及不需要使用@符号的HTML标签。
HTML标签不需要在前面加上@符号,因为它们是HTML标签。如果在ASP.Net视图中发现了@<的情况,那一定是错误的。
通过阅读“Introduction to ASP.NET Web Programming Using the Razor Syntax (C#)”可以了解更多关于Razor的知识。
另外,您可能需要阅读“How can I add a class attribute to an HTML element generated by MVC's HTML Helpers?”这篇文章,以修改HTML助手中的类,例如.LabelFor。
代码示例:
.LabelFor(model => model.Id, new { @class = "col-md-2 control-label" })