MVC3 - 从脚手架结果创建列布局的最佳方法
我已经阅读了很多与使用表格或 CSS 相关的条目/外部网站,但我想知道使用 MVC 脚手架创建的布局的最佳实践方法是什么。
下面的代码显然有一个用于标签的 div 类和另一个用于字段的 div 类,然后重复视图中的尽可能多的对。
我想要一个两列布局,因为默认的脚手架输出会创建一个非常长的页面并浪费屏幕空间。
最好的答案是创建一个表格或创建另外两个 div 并控制 CSS 中的位置,从而创建两列。
<div class="editor-label">
@Resources.Agency
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.AgencyId, ((IEnumerable<PartnerWebWI.Models.Agency>)ViewBag.PossibleAgencies).Select(option => new SelectListItem {
Text = Html.DisplayTextFor(_ => option).ToString(),
Value = option.AgencyId.ToString(),
Selected = (Model != null) && (option.AgencyId == Model.AgencyId)
}), "Choose...")
@Html.ValidationMessageFor(model => model.AgencyId)
I have read quite a few entries/external sites related to using tables or CSS but I wondered what the best practice approach was for layouts created with the MVC scaffolder.
The code below obviously has a div class for the label and another for the field which is then repeated for as many pairs as you have in the view.
I would like to have a two column layout as the default scaffolder output creates a very long page and wasted screen real estate.
Is the best answer to create a table or to create another two divs and control there position in CSS therefore creating two columns.
<div class="editor-label">
@Resources.Agency
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.AgencyId, ((IEnumerable<PartnerWebWI.Models.Agency>)ViewBag.PossibleAgencies).Select(option => new SelectListItem {
Text = Html.DisplayTextFor(_ => option).ToString(),
Value = option.AgencyId.ToString(),
Selected = (Model != null) && (option.AgencyId == Model.AgencyId)
}), "Choose...")
@Html.ValidationMessageFor(model => model.AgencyId)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是用 div 标签来做到这一点。
有一个 div 容器,然后在其中放入 2 个 div。
我会做类似下面的事情
我会做类似的事情。如果 div 与 CSS 中的不完全一样,请原谅我,但本质上,您可以使用 div 标签完成这一切,并根据您想要的页面的哪一侧设置每个 div 类或 ID,并设置它们的宽度/高度和其他属性。
I'd simply do this with div tags.
Have one div container then put 2 divs inside of there.
I'd do something like the following
I'd do something like that. Forgive me if the div's aren't exactly as they are in CSS, but essentially you do this all with div tags, and setup each div class or ID according to which side of the page you wanted and setup their width/height and other properties.
只需使用已经存在的标签并为它们添加 CSS 即可。
然后将“创建”按钮移到
您可以更改两个字段的 CSS,使其看起来更好。
Just use the labels that already exist and add CSS for them.
Then move the Create button outside of the
<fieldset>
tag. This is the code you need to move:You can change the CSS of the two fields to make it look even better.