ASP.NET MVC - 查看与母版页,如何设置标题? [英] ASP.NET MVC - View with master page, how to set title?

查看:159
本文介绍了ASP.NET MVC - 查看与母版页,如何设置标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是$ P $使用母版页时视图中设置HTML标题(头)的pfered方式?

What is prefered way of setting html title (in head) for view when using master pages?

一种方法是通过在.aspx文件中使用Page.Title,但在母版页,要求其乱用HTML code。因此,让不承担任何服务器端控件,只是纯HTML。任何更好的想法?

One way is by using Page.Title in .aspx file, but that requires in master page which can mess with HTML code. So, lets assume no server side controls, only pure html. Any better ideas?

更新:我想设置标题鉴于未在控制器或模型

UPDATE: I would like to set title in view NOT in the controller or model.

推荐答案

我们结束了

<head runat=server visible=false>

在母版页。

这样我们就可以从Page.Title读取(Page.Title要求头元素存在,否则它抛出一个异常,检查与反射)。然后,我们用我们自己的头元素 - MVC方式

This way we can read from Page.Title (Page.Title requires head element to exist, otherwise it throws an exception, checked that with reflector). We then use our own head element - MVC way.

这篇关于ASP.NET MVC - 查看与母版页,如何设置标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆