Question

I have coded a C# MVC 5 Internet Application and have a question about an ActionLink in a View.

I have the following code:

<td>
    @Html.DisplayFor(modelItem => item.mapLocations.Count)
</td>

Is it possible to create an ActionLink for this above displayed value?

Thanks in advance

EDIT

I have tried the following code:

@Html.ActionLink(item.mapLocations.Count, "Index", "MapLocation", new { mapCompanyid = item.Id }, null)

I am getting a compilation error as follows:

Compiler Error Message: CS1928: 'System.Web.Mvc.HtmlHelper<CanFindLocation.ViewModels.MapCompaniesViewModel>' does not contain a definition for 'ActionLink' and the best extension method overload 'System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string, string, object, object)' has some invalid arguments

EDIT2

Do I need the DisplayFor code to display the value in the ActionLink?

Maybe something like this:

@Html.ActionLink(Html.DisplayFor(modelItem => item.mapLocations.Count), "Index", "MapLocation", new { mapCompanyid = item.Id }, null)
Was it helpful?

Solution

This will work :-

@Html.ActionLink(item.mapLocations.Count, "// action name //", "// controller name //", new{ mapCompanyid = item.Id  }, new{ // html attributes // })

Just match your Actionlink it's structure should look like below :-

Html.ActionLink(item.mapLocations.Count, //  <--Title
            "Index",   // <-- ActionMethod
            "MapLocation",  // <-- Controller Name.
            new { mapCompanyid = item.Id }, // <-- Route arguments.
            null  // <-- htmlArguments.
            )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top