If we need to display in a page or multiple pages, such as the format of the renminbi (no ¥ back in the background) ¥ formatting, or the background data for example, such as keeping a number of small number of processing, these things are often used, especially some of the null value of processing, there may be errors. We can then encapsulate a method by creating a. cshtml file (and of course you can write the method in the current page that you want to use).
It can be called directly in the front-end of each used.
First call on this page, and write on this page using the following:
@{
Layout= "~/views/shared/_layout.cshtml";
}
@using Mycon.user
@helper Show ()
{
<p style= "color:red;" > @Model .name</p>
}
Call
@ Show ()//Note no;
If multiple views or templates are to be called, then we can define a. chhtml file in the App_Code directory, which is usually at the root of the project, so that all views or templates within the project can be called.
Below:
Add a common.cshtml file inside the App_Code folder and write the method with @helper.
@helper displayprice (Decimal pri)
{
if (pri==0)
{
<span> Price Undecided </span>
}
Else
{
<span> @string. Format ("{0:c2}", pic) </span>
}
}
@helper showmessage (int value=0)
{
@: I am @value
}