css在razor和mvc中的div应用
我是asp.net中RAZOR语法+mvc的新手。我是webforms的老手,在这方面做了很多工作,但现在我不知道如何将CSS应用到我的DIV容器中。 在我以前使用的web表单中,我喜欢:css在razor和mvc中的div应用,css,asp.net-mvc,razor,Css,Asp.net Mvc,Razor,我是asp.net中RAZOR语法+mvc的新手。我是webforms的老手,在这方面做了很多工作,但现在我不知道如何将CSS应用到我的DIV容器中。 在我以前使用的web表单中,我喜欢: div { width: 200px background-color: blue; } 现在如何在razor视图中执行此操作 我的代码: @{ ViewBag.Title = "Home Page"; } @using (Html.BeginForm("register","
div
{
width: 200px
background-color: blue;
}
现在如何在razor视图中执行此操作
我的代码:
@{
ViewBag.Title = "Home Page";
}
@using (Html.BeginForm("register","Home", FormMethod.Post, new {id="submitForm"}))
{
<div style="Width:200px">
<i>@Html.Label("Name:")</i>
@Html.TextBox("txtboxName")
</div>
<br />
<div style="Width:200px">
<i>@Html.Label("Email:")</i>
@Html.TextBox("txtboxEmail")
</div>
<br />
<div style="Width:200px">
<i>@Html.Label("Password:")</i>
@Html.Password("txtboxPassword")
</div>
<br />
<div>
<button type="submit" id="btnSubmit" name="Command" value="Submit">Submit</button>
</div>
}
@{
ViewBag.Title=“主页”;
}
@使用(Html.BeginForm(“register”、“Home”、FormMethod.Post、new{id=“submitForm”}))
{
@标签(“名称:”)
@Html.TextBox(“txtboxName”)
@Html.Label(“电子邮件:”)
@Html.TextBox(“txtboxEmail”)
@标签(“密码:”)
@Html.Password(“txtboxPassword”)
提交
}
razor是MS MVC框架的服务器端语言,它最终被解析为HTML。您的这个语法完全有效
<div style="Width:200px">
<i>@Html.Label("Name:")</i>
@Html.TextBox("txtboxName")
</div>
或者说:
@Html.Label("Name:", new {style="width:200px;"})
因此,基本上,在MVC的几乎所有助手中,您都可以传递
HtmlAttributes
(和routeValue
),有时它们会通过另一种inturn方法公开。MVC与样式包一起工作,存在您想要的所有CSS文件。看,这和剃刀无关。这只是css和html的问题。你需要澄清你的确切问题是什么。css是在正确的.css文件中还是在.cshtml中?css是否已加载?你错过了一次机会;在css中,tho.not working:/not包含标签的定义,函数有一些无效的ARGUMENTS@James,您的意思是什么?既然您使用的是@Html.Label
,您应该能够在其中传递HtmlAttributes
。什么错误@James?键入@Html.
代码建议是什么?不是标签
,单选按钮
,文本区
等。。有空吗?
@Html.Label("Name:", new {style="width:200px;"})