c# - 如何使用 asp.net MVC 通过模型属性显示 YouTube 链接?

标签 c# asp.net-mvc

我有一个名为视频的模型:

public class Video
{
    public int ID { get; set; }
    public string Title { get; set; }       
    public string Description { get; set; }
    public string VideoLink { get; set; }
    public string tags { get; set; }    
}

假设我使用 CRUD Controller ,使用上述模型,并使用 TitleDescriptionVideoLink 创建一个新视频,

创建后,URL 显示为文本而不是 YouTube 视频。

最佳答案

您可以使用video标签:

<video src="@item.VideoLink"></video>

更新:

YouTube players can be embedded in a web page using either an tag or an tag. By appending parameters to the IFrame or SWF URL, you can customize the playback experience in your application. For example, you can automatically play videos using the autoplay parameter or cause a video to play repeatedly using the loop parameter. You can also use the enablejsapi parameter to enable the player to be controlled via the IFrame Player API. more info

<object width="640" height="390">
                <param name="movie"
                       value="@item.VideoLink"></param>
                <param name="allowScriptAccess" value="always"></param>
                <embed src="@item.VideoLink"
                       type=" application />x-shockwave-flash"
                       allowscriptaccess="always"
                       width="640" height="390"></embed>
</object>

关于c# - 如何使用 asp.net MVC 通过模型属性显示 YouTube 链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32274788/

相关文章:

c# - BuildManager.AddReferencedAssembly 究竟做了什么?

asp.net-mvc - ASP.NET 4.6 目标 View 中的空传播运算符错误 BC36716

c# - EF 4.1 - 无法将一个实体与另一个现有实体相关联(可空 FK)

asp.net-mvc - 在 Html.BeginForm 中包装一些 html 的条件逻辑

asp.net-mvc - ASP.Net MVC 加载进度指示器

c# - 如何强制msbuild和nuget将引用的Lib打包为dll?

c# - TwilioRestClient SendMessage 未解析

c# - 格式化数字字符串以添加逗号 - C#

c# - ASP.NET MVC NerdDinner 教程问题

c# - WPF 从 DataTrigger 调用方法