Saturday, 4 March 2017

MVC - Simple example that shows how to access controller method directly from view

Watch this example on YouTube

1. Add to View
<h1>@Html.GetSomething()</h1>

2. In Controller add the following static class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


namespace System.Web.Mvc
{
    public static class SomeClass
    {
        public static string GetSomething(this HtmlHelper html)
        {
            return "This is something";
        }
    }
}

No comments:

Post a Comment