Watch this example on YouTube
1. Model
public interface IExtensionTest
{
void DoSomething();
}
public class ExtensionTest: IExtensionTest
{
public void DoSomething() { }
}
public static class SomethingElse {
public static string ReturnSomething(this IExtensionTest t, string s)
{
return "returning: " + s;
}
}
2. Controller
public ActionResult Index(){
IExtensionTest e = new ExtensionTest();
var res = e.ReturnSomething("bbbbb");
return View();
}
This simple example of extension methods in MVC is super helpful! Just like Razor host streamlines web hosting, these methods can simplify your code.
ReplyDelete