如何将名称设置为一个新开的标签从@ Html.ActionLink CSHTML页的TITLE [英] How to set a name to the TITLE of a newly opened tab from the @Html.ActionLink cshtml page

查看:647
本文介绍了如何将名称设置为一个新开的标签从@ Html.ActionLink CSHTML页的TITLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的code在 Index.cshtml 页:

My current code in Index.cshtml page:

@Html.ActionLinks(@Html.ActionLink(objList.Name, "Name", "ControllerName", new {Id=objList.Id}, new {target = "_blank"}))

以上code使我在新标签中单击索引链接后,打开一个页面( Name.cshtml 页。但我的目标是要指定一个名称( objList.Name )为标题新标签。
 所以,我添加了以下code中的Title属性,但预期它不工作。

The above code makes me to open a page(Name.cshtml) in a new tab after clicking a link in the Index page. But my goal is to assign a name(objList.Name) as a Title for the new tab. So, I added the Title attribute in the following code but it is not working as expected.

 @Html.ActionLinks(@Html.ActionLink(objList.Name, "Name", "ControllerName", new {Id=objList.Id}, new {target = "_blank", title = objList.Name}))

如何达致这?

推荐答案

您必须通过objList.Name作为参数传递给名称动作,这个动作可以包括在Viewbag名称:

You have to pass the objList.Name as a parameter to the "Name" action, in this action you can include the name in the Viewbag:

ViewBag.MyTitle = nameParameter;

和在名称的观点:

<title>@ViewBag.MyTitle</title>

如果您使用的是布局网页,你只有把这个在名的行动:

If you are using a Layout page, you only have to put this in the "name" action:

ViewBag.Title = nameParameter;

由于在布局视图你可能有这样的:

Because in your layout view you probably have this:

<title>@ViewBag.Title</title>

这篇关于如何将名称设置为一个新开的标签从@ Html.ActionLink CSHTML页的TITLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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