Helper implements hidden foreground effects

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.