One 、 So let's create one HtmlHelper Extension class of , Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace Practice.Helper
{
public static class MvcHelper
{
public static string SayHello(this HtmlHelper htmlHelper, string str)
{
return str;
}
}
}

Be careful : Class must be static , Methods should also be static .

Two 、 In view ( Top ) You need to quote this helper The location of , such as :

@using Practice.Helper;

Then use :

@Html.SayHello("hello")

It's simple enough ?

asp.net MVC add to HtmlHelper More articles on extended examples and usage

  1. ASP.NET MVC Razor HtmlHelper Extend and customize controls

    First look at the sample code : using System; using System.Collections.Generic; using System.Linq; using System.Web; using S ...

  2. 【ASP.NET MVC series 】 Talking about ASP.NET MVC Eight categories of extensions ( Part 1 )

    lASP.NET MVC Series articles [01] Talking about Google Chrome browser ( Theory Chapter ) [02] Talking about Google Chrome browser ( Operation )( On ) [03] Talking about Google Chrome browser ( fuck ...

  3. Walk in asp.net mvc No way back :[6]linq Common use

    asp.net mvc combination linq, Let's not talk about performance , It is quite convenient to add, delete, check and modify . Now let's introduce linq stay asp.net mvc Of Controller The common usage of the . 1 Let's start with the whole data table ...

  4. [Asp.net Mvc] adopt UrlHelper Expand to js,css Add version number to static file

    Write it at the front stay app Embedded in h5 application , The biggest headache is caching , For example, you modify a style , Or in js A method has been added to , After the release , No updates , What's loaded is still the contents in the cache . At this time, you need to clean up the cache to solve . But I don't want w ...

  5. ASP.NET MVC Web API Examples of use

    Last blog explained rest Service development , It was mentioned asp.net mvc Medium rest api, For reasons of length , I didn't explain it in the last blog , Here is a special discussion . It's the same as the last case , use asp.net mvc carry ...

  6. [ turn ]Asp.Net MVC Use HtmlHelper Rendering , And transmission FormCollection Parameter traps 【 turn 】

    stay Asp.Net MVC 1.0 Programming , We often meet scenes like this , When creating a new object , adopt HtmlHelper The way in View Rendering in the model Html Control , After filling in the relevant content , adopt Form Put the content that needs to be created Po ...

  7. [ turn ]Asp.Net MVC Use HtmlHelper Rendering , And transmission FormCollection Parameter traps

    http://www.cnblogs.com/errorif/archive/2012/02/13/2349902.html stay Asp.Net MVC 1.0 Programming , We often meet scenes like this , Building a new ...

  8. asp.net mvc Add multiple data to the database

    mvc The view of is too powerful , Personal contact .( Junior rookie , I don't know much , To the great gods ) Demand is , Customers click the Add button to pop up a box to select products and add them directly to the form , You can change the quantity of products in the form , And some information .mvc When the form is submitted, only ...

  9. MVC Customize Htmlhelper Expand

    stay MVC in , We can not only use its original method , We can also customize , This not only increases the efficiency of our development , At the same time, make the interface more concise . Specifically, what is the extension method , You can think of it this way , It must be static and the first parameter in the formal parameter is with this start , Probably first ...

Random recommendation

  1. @rpath/libswiftCore.dylib problem

    dyld: Library not loaded: @rpath/libswiftCore.dylib  Referenced from: /private/var/containers/Bundle ...

  2. mybatis-java1234 One

    One , Simple add, delete and modify code implementation package com.mybatis.mapper; import java.util.List; import com.mybatis.model.Student; pub ...

  3. MonkeyRunner Test one MonkeyRunner Use

    Recently built MonkeyRunner development environment , install PyDev when , Suffering , Now it's finally done . For some reason , It was used JDK1.6, Install plug-ins online PyDev After success ,Windows-Preferences Can't find in the PyDe ...

  4. install EPEL Source

    install EPEL Source Official source direct installation rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm ...

  5. Vue Entry notes # transition

    Vue transition , It can be found in the element from DOM Remove , The transition effect is called automatically when inserting . According to the setting , It will trigger the transition effect in time . Add... To the used target tag transition: <div transition="my_ ...

  6. use c Language writing direct insertion method

    #include<stdio.h> // Direct insertion void D_insert(int s[],int n); int main() { int i; ]; printf("pl ...

  7. easyui The text box Display prompt message data-options=&quot;prompt:&#39; Format : Water tank bracket - Jingdong auto parts store - atlas ( Big picture / atlas 6)&#39;&quot;

    <tr> <td> atlas 6:</td> <td> <input class="easyui-textbox" data-opti ...

  8. linux Tree display file tree ls tree command

    original 2016 year 07 month 27 Japan 09:50:19   yum install tree tree www │?? │?? │?? └── xml.test │?? │?? └── valgrind.su ...

  9. sublime text 3 Show spaces and Tab

    tab For needs share It's a disaster in terms of code . pyhton The clear requirement for this is not to mix it up 4 A space and tab key . Use only one of the two , It's all right . If one python The finished part of the code , It's all used 4 A space . that ...

  10. c# A two-dimensional list Sorting and timing

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...