My current code in Index.cshtml
page:
@Html.ActionLinks(@Html.ActionLink(objList.Name, "Name", "ControllerName", new {Id=objList.Id}, new {target = "_blank"}))
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}))
How to acheive this?
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:
And in the "Name" view:
If you are using a Layout page, you only have to put this in the "name" action:
Because in your layout view you probably have this:
Just add the
Name
into theRouteValueDictionary
, add it to yourActionResult
and then setViewBag.Title
.First, change your
ActionLink
to be:Then create a model (if you don't have one on the Name table), something like:
Then change your
Name
ActionResult
to be:Then add the model to your
Name
view:Then set
ViewBag.Title
in theName
view:The 'title' in your code is adding a mouseover title on the link, I think.
To have the title in the tab, use the solution from carlos (put the title tag and viewbag prop in your viewpage).