开发者

MVC Razor View - Using Model in .EditorFor() and for in String.Format()

开发者 https://www.devze.com 2023-03-26 05:11 出处:网络
<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
<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).

开发者_C百科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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消