面向.NET Framework 4的Visual Studio 2010 SP1
我被要求在短时间内支持MVC应用程序,我没有太多时间学习MVC(我已经做了很多ASPX,但没有MVC)。
应用程序生成在企业内部网中使用的一些HTML。它非常简单 - 内容已经过改进,直到它只是一个图像,每月都在变化。
这是cshtml
@model MYMVCAPP.Models.Notice
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>@ViewBag.Title</title>
</head>
<body id="content" >
@RenderBody()
</body>
</html>
渲染页面时,viewsource如下所示:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>TEST</title>
</head>
<body id="content" >
<p>
<img alt="" src="http://localhost:57223/Images/Content/3.jpg " />
</p>
</body>
</html>
但是,我需要在图像标记中添加一些属性,因此它看起来像这样:
<img border="none" src="http://localhost:57223/Images/Content/3.jpg" style="position: fixed; margin: 0px auto; min-height: 100%; height: 100%; right: 0px; left: 0px" />
有没有办法拦截对@RenderBody()的调用并操纵标签的形成?我试过了
<img border="none" src=@RenderBody() style="position: fixed; margin: 0px auto; min-height: 100%; height: 100%; right: 0px; left: 0px" />
但那不起作用:(
非常感谢
爱德华
答案 0 :(得分:1)
为什么不为它创建一个样式?
#content + p + img {
position: fixed;
margin: 0px auto;
min-height: 100%;
height: 100%;
right: 0px;
left: 0px
}