简体   繁体   English

使用带有所有页面共有的2个下拉框的mvc创建母版页/布局

[英]Creating a master page/Layout using mvc with 2 dropdownboxes common to all pages

I will like to create a masterpage/Layout and have 2 dropdown boxes on it. 我想创建一个母版页/布局,并在其上有2个下拉框。 3 other pages will be using the master page/Layout and this will be common to all these pages. 其他3个页面将使用母版页/布局,这对于所有这些页面都是通用的。

Q - I have to write code that will populate the dropdown boxes. 问-我必须编写将填充下拉框的代码。 Where do I write this since there is no code behind in mvc? 由于mvc中没有代码,我该在哪里写呢?

Thanks. 谢谢。

you need to 你需要

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.

Here's a sample master page 这是一个示例母版页

@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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM