3

hello please help me understand this, and lets hope it help others too.

in MVC what I Understood is a Model–view–controller which should be a pattern if am right. and in my mind its like:

Class in the Model Function in the Controller Layout or output in the view ASP.NET MVC Structure

but what I couldn't figure out is how to make them communicate or knowing "best practice" so I came up with this simple idea to make me understand. I have a simple video "MP4 for reference" on (C:\Users\Me\Documents\FunVid.mp4)

and I have created an ASP.NET MVC project including: - A Model. "VideoProdcast.cs" - A Controller. "VideoController.cs" - View "Razor". "VideoView.cshtml"

so if this is the :

Model : "VideoProdcast.cs"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Vidi.Models
{
    public class VideoProdcast
    {

        public int MovieId { get; set; }
        public string MovieName { get; set; }
    }
}

Controller:"VideoController.cs"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vidi.Models;

namespace Vidi.Controllers
{
    public class VideoController : Controller
    {
         // GET: Video
         public ActionResult VideoView()
         {
             var Movie = new Movie() { Name = "Movie" };
             return View(Movie);
         }
    }
}

View: "VideoView.cshtml"

@{
ViewBag.Title = "VideoView";
}

<h2>VideoView</h2>

So given the fact that my movie is on (C:\Users\Me\Documents\FunVid.mp4) what is the best practise to show this movie on my view, using(MVC Structure) the view to call funVid.mp4 as a controller or function by movie name from the model. "and please do help me if am wrong in stating anything?" Note that video format is not a must "any supported formate will work just fine ".

I dont know if I made it easier or harder to understand but this is how am imagining it. thanks in advance I really do appreciate your help.

1
  • ASP.NET MVC isn't true "MVC" - the ViewModel is not the Model - it serves as an intermediary between the Controller and the View. The Model itself is often your business entity objects, which does not apply to your scenario. So it's better described as "MCVmV" (Model-Controller-ViewModel-View) instead... Commented Nov 10, 2016 at 1:36

2 Answers 2

1

Not sure if this is a best practice:

  1. Add URL to your model as string.

  2. In your controller, populate your model with the path to your video, from wherever they are stored, or simply

    var Movie = new VideoProdCast() { NameName = "Movie", URL = "C:\yourpath\yourvideo.mp4", id = 1 }; return View(Movie);

  3. In your view, set your video src=model.url, also reference the model at the top of the view.

Sign up to request clarification or add additional context in comments.

Comments

1

You're very much on the right track. The two primary things you are missing, are the path to the file, as you stated, and completing the model binding you started.

As for the file path, this should be a property of the VideoProdcast Model:

public class VideoProdcast
{
    public int MovieId { get; set; }
    public string MovieName { get; set; }
    public string MoviePath { get; set; }
}

Then, add the following line to your View:

@model Vidi.Models.VideoProdcast

This gives you access to the Movie model object that you passed to the view in the controller (return View(Movie);). Since you've added the path to the file, you can now add something like this to your view:

<video src="@Model.MoviePath">@Model.MovieName</video>

or something like that to show the video on the page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.