<div> <!--Declare the method in the view, the type of this method is fixed to helperresult--> @helper Showhello (string s) { <div> wow!!! @s </div> } </div> <div> <!--call the method declared in the view-- @ShowHello ("cfs") </div>
:
<div> <!--Declare the method in the view, the type of this method has been fixed to helperresult--> @helper Showhello (string s, int b) {
<div> WOW!!! @s @b </div> } </div> <div> <!--call the method declared in the view-- @ShowHello ("cfs",</div) >
:
Note: Generally we rarely declare methods in the view, the method contains the logic, if the method is declared in the view, the logic will be put into the view, contrary to the original intention of using MVC, but we declare in the view of the method is generally to do some repetitive HTML code output, not involved in the specific business, The reason why razor supports defining methods on a view is to solve the problem of repeating the output of HTML code on the view.
MVC, how do I declare a method in a view and invoke a method?