2015-08-28 14 views
2

我有一個名爲視頻模式:如何使用asp.net MVC通過模型屬性顯示YouTube鏈接?

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控制器,使用上述模型,並創建TitleDescription,並且VideoLink一個新的視頻,

創建後,該網址會顯示爲一段文字,而不是YouTube視頻。

+0

你爲什麼不使用用於顯示視頻''

+0

謝謝大家的時間和幫助。 – john

回答

2

您可以使用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> 
+0

謝謝你的回覆,我試過這個,但即時獲取小黑盒子,我錯過了什麼? – john

+0

@john嵌入youtube視頻有點不同,請檢查我的答案。 –

+0

任何其他提示? – john

1

試試這個:得到標記用於嵌入來自here一個視頻,然後不喜歡下面的例子。

<html> 
    <body> 
    <iframe src="@Model.VideoLink" width="560" height="315" frameborder="0" allowfullscreen></iframe> 
    </body> 
</html> 

看你如何用你的模型中的URL替換幀源。

您可能還需要更多的數據添加到您的模型來定義像允許全屏等

+0

現在我得到了大的空白區域,視頻的維度,但不是視頻本身,謝謝,顯然我做錯了什麼。 .. – john

+0

在鉻控制檯我得到這個錯誤: 拒絕在框架中顯示'https://www.youtube.com/watch?v=0WWzgGyAH6Y',因爲它將'X-Frame-Options'設置爲'SAMEORIGIN'。 – john

+0

好的,請轉到YouTube並找到此視頻的嵌入鏈接,並將其粘貼到視圖中。這應該顯示視頻。然後用您存儲的網址替換源文件。 – Ares