asp.net mvc 4 - How to send my two models in one view in mvc4? -



asp.net mvc 4 - How to send my two models in one view in mvc4? -

managedatabase db = new managedatabase(); // // get: /addcart/ public actionresult index() { list<userprofile> userdetails = db.userprofiles.where(m => m.username == user.identity.name).tolist(); var _product = ord in db.orders ord.userid == userdetails[0].userid select ord; homecoming view(_product); }

i have 2 models userprofile , orders.i want retrieve orders table orders userid= logged userid..but tells 2 models not allowed 1 view....pls tell me solution or tell me alternate method.

create viewmodel class:

public class userordersvm { list<userprofile> userdetails {get;set;} list<order> orders {get;set;} }

and in action:

public actionresult index() { list<userprofile> userdetails = db.userprofiles.where(m => m.username == user.identity.name).tolist(); var _product = (from ord in db.orders ord.userid == userdetails[0].userid select ord).tolist(); userordersvm vm = new userordersvm() { userdetails =userdetails , orders = _product } homecoming view(vm); }

and in view:

@model userordersvm

asp.net-mvc-4

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -