命名参数规范必须的WebGrid MVC3所有固定参数之后出现 [英] Named arguments specifications must appear after all fixed arguments in WebGrid MVC3
问题描述
我要显示如果网格列的值是真,则是别人否。试图的WebGrid
但鉴于扔我的错误在的GridColumn
。
// code:
grid.Column(SelectedStatus,标题:选定状态,Model.SelectedStatus ==真Html.Raw(是):Html.Raw(否 ))
当我试图用格式为:
在它扔我列参数无效
误差
在那里我错了?
有几件事情。首先这是相当明显的错误信息 - 你明白,你需要在最后添加一个名为参数,因为固定的参数可以命名参数后没有出现
二,format参数是不是一个字符串而是需要一个类型 System.Func<对象,对象>
这样你就可以将其替换为:
grid.Column(SelectedStatus,选定状态,M => m.SelectedStatus ==真Html.Raw(是):Html.Raw(没有))
您会注意到我删除了名为头
参数太多,因为它已经在列表中的第二个参数反正所以它是多余的在这里。
最后,如果 Model.SelectedStatus
是布尔
(而不是布尔?
)没有必要为 ==真
。你可以简单地写:
M => Html.Raw(?m.SelectedStatus是:否)
I have to display if the Grid column value is "true" then "Yes" else "No". Tried in WebGrid
but throwing me error in the GridColumn
in View.
//Code:
grid.Column("SelectedStatus", header: "Selected Status", Model.SelectedStatus==true ? Html.Raw("Yes"): Html.Raw("No"))
When i tried to use format:
in the column it is throwing me "Invalid arguments"
error.
Where i'm wrong?
A few things. Firstly the error message which is fairly obvious - you understood that you needed to add a named argument at the end because fixed arguments cannot appear after named arguments.
Second, the format parameter is not a string but rather of expects a type System.Func<Object, Object>
so you can replace it with:
grid.Column("SelectedStatus", "Selected Status", m => m.SelectedStatus == true ? Html.Raw("Yes") : Html.Raw("No"))
You'll notice I removed the named header
parameter too, because it's already the second argument in the list anyway so it is redundant here.
Finally, if Model.SelectedStatus
is a bool
(rather than a bool?
) there is no need for the == true
. You can simply write:
m => Html.Raw(m.SelectedStatus ? "Yes" : "No")
这篇关于命名参数规范必须的WebGrid MVC3所有固定参数之后出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!