You want to implement the following functionality: as shown in
Click the End button to make the above red jump to the end of the active button above, the foreground code is used in the use of an action to achieve, but I changed something, so that can not jump.
Front Code
<ul class= "Nav nav-tabs" > <li class= "active" > <a href= "#tab_1" data-toggle= "tab" > 4 Columns </a> </li> <li> <a href= "#tab_2" data-toggle= "tab" > 3 Columns </a> </li> <li> <a href= "#tab_3" data-toggle= "tab" > 2 Columns </a> </li> </ul>
To implement that feature, you must put the class= "active" in the LI tag into the following li. But I want to let the user click at the foreground to make the color change.
After the discussion with friends, you can use @helper to achieve.
1: First define a variable currenttext in the view, so that it equals viewbag.text, which we can pass in the controller.
@{ string Currenttext=viewbag.text;}
2: In the controller, we observe that the click to pass to the controller is the parameter, we determine the parameters to communicate with each other in the view of the Viewbag.text. I'm going to change this here based on the state parameters passed.
if (model. Activitystate = = Activitystate. In progress) { Viewbag.text = "active"; } else { Viewbag.text = "Activeend"; }
3: Write the code in view that you want to replace.
@helper MenuItem (String currenttext, String allowtext) { @Html. Raw (Currenttext = = Allowtext?) "Active": "") }
Here is the use of @helper function, directly defined a method, which has two parameters, Currenttext,allowtext. The first one we pass through the controller. The second we write to death in the place where we are going to use, for example, I am going to write the death in the <li> directly.
<ul class= "Nav nav-tabs" > <li class= "@MenuItem (Currenttext," active ")" > <a href= "@Url. Action ("Index", "activity", new {id=model.id,activitystate=activitystate. In progress}) "> active </a> < /li> <li class= "@MenuItem (Currenttext," Activeend ")" > <a href= "@Url. Action (" Index "," Activity " , new {id = model.id, activitystate = activitystate. Closed}) "> Closed activities </a> </li> </ul >
4: Actually is equivalent to call us in the foreground defined method, directly passed the parameters, and then the method inside the three-dimensional expression of the judgment.
Effect:
Helper implements hidden foreground effects