I just started programming at MVC and I would like to ask about the best way to call a controller's method from your view. To make it easier: I have a model called Song with 2 methods to start and stop it:
public class Song
{
WMPLib.WindowsMediaPlayer wplayer ;
public Song() {
wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "my song url";
wplayer.controls.stop();
}
public void Stop() {
wplayer.controls.stop();
}
public void Start() {
wplayer.controls.play();
}
}
In the controller I create the song object and I have two functions to start and stop it.
public class DefaultController : Controller
{
// GET: Default
Song c = new Song();
public ActionResult Index()
{
return View(c);
}
public void Start() {
c.Start();
}
public void Stop() {
c.Stop();
}
}
In the view I have 2 buttons that correspond to each controller action.
<button type="button">Start</button>
<button type="button">Stop</button>
How can I do the most correct way to call each controller action from the view buttons?
Thank you very much for your attention, I appreciate your help