我想创建一个母版页/布局,并在其上有2个下拉框。 其他3个页面将使用母版页/布局,这对所有这些页面都是通用的。
问:我必须编写将填充下拉框的代码。我在哪里写这个,因为mvc中没有代码?
感谢。
答案 0 :(得分:0)
你需要
1) Create _Layout.chtml in your shared folder, which should exist if you create a new asp.net app
2) have the 3 pages point to the new layout file by setting "Layout" on the page or set it in _ViewStart.chtml
3) pass data to your view and master page and this can be done by referencing the @Model on your view and layout page. if anything, you can always use the generic ViewBag container.
这是一个示例母版页
@model SomeClassType
<!DOCTYPE html>
<html class="landing-page">
<head>
@Html.Partial("_MetaData")
<title>@ViewBag.Title</title>
</head>
<body >
<div>
@Model.SomeProperty
</div>
@RenderBody()
</body>
</html>