如何在Visual Studio中的ASP.NET MVC视图旁边添加代码? [英] How to add code beside to ASP.NET MVC view in Visual Studio?
问题描述
我想在ASP.NET MVC项目中使用文件旁边的代码作为视图.在Visual Studion 2008中,有什么简单的方法可以将文件旁边的代码添加到视图中?
I want to use code beside files for my views in my ASP.NET MVC project. Is there any simple way in Visual Studion 2008 how to add a code beside file to the view?
注意:我知道ASP.NET MVC中不建议使用除文件以外的代码,但是我的原因是我希望将.aspx文件提供给设计人员,并且不想让他尽可能避免混淆非HTML代码.此处.
推荐答案
将一个类添加到您的视图文件夹并命名(例如)Foo,并确保该类继承ViewPage或ViewPage,以防万一您的View是一个坚固的视图.键入一个.
Add a class to your view folder and name it (for example) Foo and make sure that this class inherits ViewPage or ViewPage in case if your View is a strongly typed one.
然后在aspx标记中将@page伪指令的继承属性更改为Foo.cs
Then in the aspx markup change the inherits from attribute of the @page directive to Foo.cs
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Foo" CodeBehind="~/Views/Home/Foo.cs" %>
希望这会有所帮助.
这篇关于如何在Visual Studio中的ASP.NET MVC视图旁边添加代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!