gpt4 book ai didi

javascript - 如何在页面加载时显示随机电影

转载 作者:行者123 更新时间:2023-12-02 17:07:30 26 4
gpt4 key购买 nike

我想在页面加载时显示 AppDomain.BaseDirectory 中的随机电影。

  RandomVideo.cshtml 

<video width="320" height="240" controls>
<source src="MyMovie1.mp4" type="video/mp4"> */ MyMovie1 should not be hard coded*/
</video>

最佳答案

这是我的做法:

查看

@model VideoModel

<video width="320" height="240" controls>
<source src="@Model.VideoSource" type="video/mp4">
</video>

型号

public class VideoModel
{
public string VideoSource { get; set; }
}

Controller

public class VideoController : Controller
{
public ActionResult PlayVideo()
{
var model = new VideoModel();

var videos = Directory
.GetFiles(AppDomain.CurrentDomain.BaseDirectory)
.Where(f => f.EndsWith(".mp4"))
.ToList();

var randomVideo = videos[new Random().Next(0, videos.Count)];

model.VideoSource = randomVideo;

return View(model);
}
}

关于javascript - 如何在页面加载时显示随机电影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25115346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com