Saturday, 15 August 2015

asp.net mvc - DisplayFor silently fails for cast model -



asp.net mvc - DisplayFor silently fails for cast model -

my application has 2 types of contacts, employees , customers.

so have:

icontact

contact : icontact

customer : contact

employee : contact

i have created view effort display right template depending on type of model. silently fails , nil displayed.

@model icontact @{ var client = model customer; var employee = model employee; } @if (customer != null) { @html.displayfor(model => customer, "customerinfo") } else if (employee != null) { @html.displayfor(model => employee, "employeeinfo") }

i'm sure should easy, don't know right way it.

the displayfor helper searching property matches customer or employee never find it. should instead render view partial. allows select view want render , pass typed model:

@if (customer != null) { @html.partial(customerinfo", customer) } else if (employee != null) { @html.partial("employeeinfo", employee) }

asp.net-mvc razor

No comments:

Post a Comment