2
@Html.DisplayFor(modelItem => item.vouchertype == "P" ? "Paid" : "Receipt")

&

@Html.DisplayFor(modelItem => item.dated.ToString("dd-MMM-yy"))

Trying to format the value but error occurs:

Template can use only with field access, property access, single dimension array index or single parameter custom indexer experssions.

1 Answer 1

1

I assume posted lines are part of forech or other loop, and we speak about single item at that point.

In your Lambda expression you should use modelItem variable instead on item

@Html.DisplayFor(modelItem => modelItem.vouchertype == "P" ? "Paid" : "Receipt")

&

@Html.DisplayFor(modelItem => modelItem.dated.ToString("dd-MMM-yy"))

In Lambda expression rule is following:

x => x become your variable

https://msdn.microsoft.com/en-us/library/bb397687.aspx

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

1 Comment

thanks for knowlegding me about lambda experession . this worked : @(item.dated.ToString("dd-MMM-yy"))

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.