c# - asp.net 2 Properties refer same class -
i have 1 model class called client.
namespace logistic.models { public class client { public int clientid { get; set; } public string name { get; set; } public string lastname { get; set; } public icollection<dispatch> dispatches { get; set; } } }
i have class has 2 properties relationship client:
namespace logistic.models { public class dispatch { public int dispatchid { get; set; } public int customerid { get; set; } public int recipientid { get; set; } public client customer { get; set; } public client recipient { get; set; } } }
in order have relationship in dispatch class have have clientid. right? in case have 2 clientid. started asp.net mvc, , can't understand it.
because in controller have:
public actionresult dispatch() { db.dispatches.include("customer").tolist(); db.dispatches.include("recipient").tolist(); var dispatch = db.dispatches; return view(dispatch); }
and in view trying display:
@model ienumerable<logistic.models.dispatch> @{ viewbag.title = "dispatch"; } <h2>dispatch</h2> @foreach(var item in model) { <h2>tracking : @item.trackingid</h2> <br /> <h2>customer : @item.customer.name</h2> <br /> <h2>recipient : @item.recipient.name</h2> <br /> }
Comments
Post a Comment