title: Put a video in a View and play it Aspnet.core
body: <p>I have an exercise class and a view that allows me to create exercises.
  One of the variables is a video, how can you insert a video in order to save it in the database and present it in the view?
  In exercise class I have</p>
  
  <pre><code>[Table("Exercicios_Ginasio")]
      public partial class ExerciciosGinasio
      {
          public ExerciciosGinasio()
          {
              Inclui = new HashSet&lt;Inclui&gt;();
          }
  
          [Key]
          [Column("IDExercicios_Ginasio")]
          public int IdexerciciosGinasio { get; set; }
          [Required]
          [Column("nome")]
          [StringLength(30)]
          public string Nome { get; set; }
          [Required]
          [Column("texto_descritivo")]
          [StringLength(1000)]
          public string TextoDescritivo { get; set; }
          [Required]
          [Column("foto")]
  
          public string Foto { get; set; }
          [Required]
          [Column("video")]
  
          public string Video { get; set; }
  
          [InverseProperty("IdexerciciosGinasioNavigation")]
          public virtual ICollection&lt;Inclui&gt; Inclui { get; set; }
      }
  }
  </code></pre>
  
  <p>In the controller Exercises I used the function Create automatically generated in the creation of the controller
  In the method I added code to save the image in the database</p>
  
  <pre><code>  [HttpPost]
          [ValidateAntiForgeryToken]
          public async Task&lt;IActionResult&gt; Create([Bind("IdexerciciosGinasio,Nome,TextoDescritivo,Foto,Video")] ExerciciosGinasio exerciciosGinasio, IFormFile fotografia,IFormFile video)
          {
              string caminho = Path.Combine(_hostEnviroment.ContentRootPath, "wwwroot\\Exercicios");
  
              string nome_ficheiro = Path.GetFileName(fotografia.FileName);
              string caminho_completo = Path.Combine(caminho, nome_ficheiro);
  
              FileStream fs = new FileStream(caminho_completo, FileMode.Create);
              fotografia.CopyTo(fs);
              exerciciosGinasio.Foto = caminho_completo;
              fs.Close();
  
  
  
  
              string caminho2 = Path.Combine(_hostEnviroment.ContentRootPath, "wwwroot\\Exercicios");
  
              string nome_ficheiro2 = Path.GetFileName(video.FileName);
              string caminho_completo2 = Path.Combine(caminho2, nome_ficheiro2);
  
              FileStream _fs = new FileStream(caminho_completo2, FileMode.Create);
              video.CopyTo(_fs);
              exerciciosGinasio.Video = caminho_completo2;
              _fs.Close();
  
              if (ModelState.IsValid)
              {
  
                  _context.Add(exerciciosGinasio);
                  await _context.SaveChangesAsync();
                  return RedirectToAction(nameof(Index));
              }
              return View(exerciciosGinasio);
          }
  </code></pre>
  
  <p>So how do I put it in the view to insert a video and save it in the database?
  In order to be able to present it in the index</p>
  
  <pre><code>@model WebApplication1.Models.ExerciciosGinasio
  
  @{
      ViewData["Title"] = "Create";
  }
  &lt;h4&gt;Criar Exercicio&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-md-4"&gt;
          &lt;form asp-action="Create" enctype="multipart/form-data"&gt;
              &lt;div asp-validation-summary="ModelOnly" class="text-danger"&gt;&lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Nome" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="Nome" class="form-control" /&gt;
                  &lt;span asp-validation-for="Nome" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="TextoDescritivo" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="TextoDescritivo" type="text" class="form-control" /&gt;
                  &lt;span asp-validation-for="TextoDescritivo" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Foto" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="Foto" type="file" class="form-control" accept=".png, .jpg, .bmp" value="" /&gt;
                  @*&lt;span asp-validation-for="Foto" class="text-danger"&gt;&lt;/span&gt;*@
  
                  &lt;div&gt;
                      &lt;input type="hidden" name="fotografia" value="0" /&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label asp-for="Video" class="control-label"&gt;&lt;/label&gt;
                      &lt;input asp-for="Video" type="file" class="form-control" /&gt;
                      @*&lt;span asp-validation-for="Video" class="text-danger"&gt;&lt;/span&gt;*@
                  &lt;/div&gt;
                  &lt;div&gt;
                      &lt;input type="hidden" name="video" value="0" /&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;input type="submit" value="Create" class="btn btn-primary" /&gt;
                  &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;div&gt;
      &lt;a asp-action="Index" asp-controller="Home"&gt;Voltar&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  &lt;br /&gt;
  @section Scripts {
      @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
  }
  </code></pre>
  
  <p>I tested it this way, and I got this error</p>
  
  <p>NullReferenceException: Object reference not set to an instance of an object.
  WebApplication1.Controllers.ExerciciosGinasiosController.Create(ExerciciosGinasio exerciciosGinasio, IFormFile fotografia, IFormFile video) in ExerciciosGinasiosController.cs, line 64</p>
  
  <pre><code>WebApplication1.Controllers.ExerciciosGinasiosController.Create(ExerciciosGinasio exerciciosGinasio, IFormFile fotografia, IFormFile video) in ExerciciosGinasiosController.cs
     string nome_ficheiro = Path.GetFileName(fotografia.FileName);
  </code></pre>
  
  <p>Can someone help me solve it?</p>