asp.net-mvc-3 – 在剃刀视图中使用泛型方法
发布时间:2020-12-16 07:09:51 所属栏目:asp.Net 来源:网络整理
导读:有没有办法让razor视图中的using语句与泛型方法一起使用?例如,我想要webforms代码段 % using(Html.BeginFormController(c = c.Method())) { % Some code% } % 像这样转换成剃刀 @using(Html.BeginFormController(c = c.Method())){ Some code} 但这不起作用
有没有办法让razor视图中的using语句与泛型方法一起使用?例如,我想要webforms代码段
<% using(Html.BeginForm<Controller>(c => c.Method())) { %> Some code <% } %> 像这样转换成剃刀 @using(Html.BeginForm<Controller>(c => c.Method())) { Some code } 但这不起作用,因为剃刀解释< Controller>作为HTML标记.添加括号也不起作用,因为razor不包括开始和结束BeginForm的大括号.以下是我尝试过的不同方法,我再也想不到了. @using(Html.BeginForm<Controller>(c => c.Method())) // Interpreted as c# to '<Controller>' { // interpreted as HTML Some code // interpreted as HTML } // interpreted as HTML @(using(Html.BeginForm<Controller>(c => c.Method()))) // Interpreted as c# { // interpreted as HTML Some code // interpreted as HTML } // interpreted as HTML @{using(Html.BeginForm<Controller>(c => c.Method())) // Interpreted as c# { // interpreted as c# Some code // interpreted as c# } // interpreted as c# } // interpreted as c# @(using(Html.BeginForm<Controller>(c => c.Method()))) // Interpreted as c# @{ // interpreted as c# Some code // interpreted as c# } // interpreted as c# aynone知道怎么做吗? 更新:看来上面的第三种方法是这样做的方式. Razor显然是这样的: @{using(Html.BeginForm<Controller>(c => c.Method())) // Interpreted as c# { // interpreted as c# <p> // interpreted as HTML Some text // interpreted as HTML @Code // interpreted as c# </p> // interpreted as HTML } // interpreted as c# } // interpreted as c# 不是最明显的做事方式,但它有效. 更新2:Razor可能已在某个时候更新,因为现在上面的选项#1按预期工作. @using(Html.BeginForm<Controller>(c => c.Method())) { Some code } 解决方法
如果你将整个陈述包装在parens中怎么办:
@(using(Html.BeginForm<Controller>(c => c.Method()))) 或者使用代码块? HTH. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 将下拉列表中的SelectedItem绑定到MVC 4中的
- 如何在ASP.NET MVC 4和jquery中使用web api下载文件
- asp.net-mvc – 城堡温莎IoC在一个MVC应用程序
- asp.net-mvc – Cookie不会被删除
- 与VS集成的若干种代码生成解决方案[博文汇总(共8篇)]
- asp.net – Knockout.js – 数据绑定的javascript函数
- asp.net-mvc – 从子页面选择MVC中母版页上的右侧菜单
- asp.net-mvc – 如何降级Visual Studio 2012中的Entity Fra
- asp.net-mvc – ASP.NET MVC Spark视图引擎
- ASP.net WebAPI跨域调用问题的解决方法