title: Handle a click event on a button in C# with Razor and MVC
body: <p>how can I handle an event which is triggered in a view from a different controller class/file?</p>
  
  <p>Controller class (where the event is supposed to be handled):</p>
  
  <pre><code>using System.Web.Mvc;
  using TestApp.Models;
  
  namespace TestApp.Controllers
  {
  public class HelloWorldController : Controller
  {
      // GET: HelloWorld
  
      Movie movie;
  
      public ActionResult Index()
      {
          movie = new Movie();
          setMovie();
  
          ViewBag.Message = "ID: " + movie.ID + "\r\nTitle: " + movie.Title +
              "\r\nRelease Date: " + movie.ReleaseDate + "\r\n: " + movie.Price;
  
  
  
          return View();
      }
  
      public ActionResult Welcome(string name, int numTimes = 1) {
          ViewBag.Message = "Hello" + name;
          ViewBag.NumTimes = numTimes;
  
          return View();
      }
  
      public void modifyMovieClicked()
      {
          System.Diagnostics.Debug.WriteLine("test");
      }
  
      private void setMovie()
      {
          movie.ID = 9821;
          movie.Title = "Scarface";
          movie.ReleaseDate = "October 20";
          movie.Price = 85;
  
      }
  }
  }
  </code></pre>
  
  <p>View Class(where the html button is defined)</p>
  
  <pre><code>@using TestApp.Controllers;
  
  @{
  Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  @{
  ViewBag.Title = "Movie List";
  }
  
  @{ 
  HelloWorldController controller = new HelloWorldController();
  
  void clickedButton()
  {
      controller.modifyMovieClicked();
  }
  }
  
  
  &lt;h2&gt;My Movie List&lt;/h2&gt;
  
  &lt;p&gt;
     @ViewBag.Message
  &lt;/p&gt;
  
  &lt;button id= "modifyButton" runat ="server" 
   onserverclick="clickedButton"&gt; Modify movie&lt;/button&gt;
  </code></pre>
  
  <p>When clicked, the html button is supposed to call the clickedButton method so this method can call the event handler in the other file, but this doesnt happen. Any help is appreciated</p>