asp.net-mvc – 实用程序方法可以在MVC剃刀中返回原始html
发布时间:2020-12-16 07:28:34 所属栏目:asp.Net 来源:网络整理
导读:我试图使用MVC razor of autoplay =’autoplay’向页面输出一个值,以便自动播放 HTML5视频.我的方法GetAutoPlayVideo读取web.config文件以确定该站点是否将自动播放视频. public static string GetAutoPlayVideo(){ bool autoPlayVideo = Converter.ToBoolea
我试图使用MVC razor of autoplay =’autoplay’向页面输出一个值,以便自动播放
HTML5视频.我的方法GetAutoPlayVideo读取web.config文件以确定该站点是否将自动播放视频.
public static string GetAutoPlayVideo() { bool autoPlayVideo = Converter.ToBoolean(System.Web.Configuration.WebConfigurationManager.AppSettings["AutoPlayVideo"]); if (autoPlayVideo) return "autoplay='autoplay'"; else return string.Empty; } 然后在页面上使用以下标记: <div id="videoHolder"> <video id="video" width="503" height="284" @Html.Raw(MyUtility.GetAutoPlayVideo()) controls > @foreach (string s in Model.SelectedShow.VideoFiles) { <source src="@(CdnResources.GetImageUrl(s))" type="@(Utility.GetMimeType(s))" /> } Your browser does not support the video tag. </video> </div> 我到目前为止创建的语法是这样的: @Html.Raw(MyUtility.GetAutoPlayVideo()) 有可能缩短这个类似的东西吗? @MyUtility.GetAutoPlayVideo() 解决方法
是.
Razor转义系统不会转义IHtmlString类型的任何内容. Html.Raw()方法只返回包含文本的HtmlString实例. 您可以简单地将您的方法声明为返回IHtmlString,并调用Html.Raw()(或新的HtmlString()). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在ASP.NET中生成图像缩略图?
- asp.net-mvc – 有没有人使用史蒂夫·桑德森的MvcIntegrati
- IIS 7.5应用程序初始化ASP.NET Web服务(预热),而不重新映射
- asp.net – 如何在.net WebApi2应用程序中使用OAuth2令牌请
- 在ASP.NET中流文件的最佳方式
- 如何部署/发布ASP.NET网站?
- asp.net-mvc – 使用HTML.Grid显示子对象
- asp.net – 自定义主体在新请求时恢复为GenericPrincipal
- asp.net-mvc – 存储库与DAL中的服务模式:EF和Dapper
- asp.net – AJAX updatepanel给出错误
推荐文章
站长推荐
- asp.net – 为什么压缩ScriptResource.axd,即使禁
- asp.net – 自定义会话状态模块 – 使用ASP状态服
- 为什么我不能在运行时编辑我的ASP.NET Web应用程
- asp.net-mvc-3 – 使用Ninject 2.2的MVC 3依赖注
- asp.net – web.config不转发到非.aspx页面上的4
- asp.net-mvc-4 – 缺少尾部斜杠的MVC错误行为的解
- asp.net-web-api – 使用Asp.Net Core WebAPI进行
- asp.net – 我可以在GoDaddy上使用NHibernate吗?
- 从asp页面调用C#函数
- ASP.NET会话ID在浏览器选项卡之间共享
热点阅读