Before I start, I know this NOT considered good practice, but was wondering how (if at all) it would be possible to define a method inside my view.
Im using C# in ASP.Net MVC
The following does not seem to work:
decimal DoCalculation(IEnumerable<MyItems> items){
...
}
N.B. I AM NOT USING THE RAZOR VIEW ENGINE
If you are using the Razor view engine you could declare
inline functions:or also you could use
inline helpers:And if you are using the WebForms view engine:
Obviously writing C# code in views is as bad as not writing any code at all. Worth mentioning for other people reading this so that they do not do the same mistake as you.