1
<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.

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, that works. I thought the @model at the top of the view page is declaration of the variable.
I remember seeing "x => x.Property" example as well, if that works, does this mean all Lambda expression refers to Model? Or all undeclared variable using like m or x, would refer to the model?
Neither. A lambda expression is a function that takes an argument named x or m or whatever. The name of the argument is totally irrelevant. Most MVC helper methods take lambda expressions that receive the model as their parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.