0

In my MVC 5 app I have the following menu item:

<li>@Html.ActionLink("Access Instance", "AccessInstance", "AccessInstance")</li>

I need to hide it using jquery .hide() method. What can I add to this

<li>

to have jquery find it (i.e. I'm new to MVC and do not know the proper syntax of adding an id attribute to @Html.ActionLink helper

1 Answer 1

2

HTMLAttributes are the fourth value that you can provide to the ActionLink, so you might do something like

@Html.ActionLink("Access Instance","AccessInstance",null, new {id = "AccessInstanceListItem})

The first value is the text displayed for the link. The second value is the name of the action (the ActionResult method in your controller). The third value in this case is a null route value object (you dont need it unless you have to pass some values to your action). The last value is an HtmlAttributes object, which will take whatever attributes you want to provide. You can give it whatever id you want, but I went with AccessInstanceListItem.

The code you have provided where the 3rd input parameter is "AccessInstance" would only be necessary if your view isn't in Views\AccessInstance. If they follow the same folder pattern, the name of the controller is assumed without you needing to provide it.

Then in jquery you can do this

$("#AccessInstanceListItem").hide();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.