Html.ActionLink with ViewBag

I currently have a ActionLink in Razor that looks like this:

@Html.ActionLink("Back to News", "Index")

However, I wish to add a ViewBag to it

@ViewBag.groupid

Thus the rendering of the ActionLink to know to instead of being simply:

<a href="/">Back to News</a>

To instead have changed the URL to be Index/@ViewBag.groupid ( Index/5 )

so that URL is then

/Index/5   ( where 5 is the ViewBag.groupid)   

Answers


There's an overload (a few actually) that take routeValues. Set routeValues to a new anonymous object with an id property set to ViewBag.groupid.

@Html.ActionLink("Back to News", "Index", "controller name", 
                 new {id = ViewBag.groupid}, null)

use this format : @Html.ActionLink("title", actionMethodName","ControllerName", new { id = value }, null); for your example it would be : @Html.ActionLink("back to news", "Index", "your controller name", new { id = @ViewBag.groupid }, null);


Need Your Help

SSL Configuration issue in AEM6

ssl cq5 aem

I am having issues in configuring my AEM instance SSL configured. I am using below command to generate the keystore.

c# finding random number

c# random

First of all i am learning c# and i got a homework assignment. But i didn't figure it out myself. I can't find the random numbers. Shall i write it in an apart class or actually i have no idea wher...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.