MVC Razor 视图 - 在 .EditorFor() 和 for String.Format() 中使用模型
<td>@Html.EditorFor(Model => Model.Loan)</td>
我在视图的开头有这个,然后之后,我有一个这样的声明
The interest rate for the loan is @String.Format("{0:c}", Model.Interest).
它给了我错误“'Model'与声明'System.Web.Mvc.WebViewPage.Model'冲突”
我也尝试过
The interest rate for the loan is @String.Format("{0:c}", Model => Model.Interest).
它错误“无法将 lambda 表达式转换为类型“object[]”,因为它不是委托类型”
如果我删除 EditorFor,则下一条语句不会出错。
除了将模型添加到 ViewBag 之外,还有什么方法可以同时实现这两者吗?
<td>@Html.EditorFor(Model => Model.Loan)</td>
I have that in the beginning of the view, and then after that, I have a statement like
The interest rate for the loan is @String.Format("{0:c}", Model.Interest).
It gives me error "'Model' conflicts with the declaration 'System.Web.Mvc.WebViewPage.Model'"
I also tried
The interest rate for the loan is @String.Format("{0:c}", Model => Model.Interest).
It errored "Cannot convert lambda expression to type 'object[]' because it is not a delegate type"
If I remove the EditorFor, it doesn't error for the next statement.
Is there any way I can do both, other than adding the model to the ViewBag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
lambda 表达式中的参数名称与现有
Model
属性冲突。您需要使用不同的参数名称,例如@Html.EditorFor(m => m.Loan)
The argument name in the lambda expression is conflicting with the existing
Model
property.You need to use a different argument name, such as
@Html.EditorFor(m => m.Loan)