Hi guys Today I would like to go through passing several models through a controller and onto a view
Where to use this?
Suppose I have a home page where I want a modal to appear for register and another modal for login
These require two separate modals to be passed therefore consider the ffg models
I'm using prop to show props declared
Public class loginView
{
Prop username;
Prop password;
}
Public class registerView
{
Prop fullname;
Prop...;
Prop...;
}
We now create a new model
Public class HomepageModel
{
Public loginView loginmodel{get;set;}
Public registerView registermodel{get;set;}
}
Suppose the controller used is Home controller with Home actionResult
To use this modal to call it like this.
Public ActionResult Home(HomepageModel objmodel)
{
objmodel.registermodel.Fullname.......
//or
objmodel.loginmodel.Username
}
And for the view the same but referenced at the top
None
0 Points
4 Posts
MVC 5 passing several modals to controller and views
Jul 03, 2015 12:55 PM|teezy7|LINK
Where to use this?
Suppose I have a home page where I want a modal to appear for register and another modal for login
These require two separate modals to be passed therefore consider the ffg models
I'm using prop to show props declared
Public class loginView
{
Prop username;
Prop password;
}
Public class registerView
{
Prop fullname;
Prop...;
Prop...;
}
We now create a new model
Public class HomepageModel
{
Public loginView loginmodel{get;set;}
Public registerView registermodel{get;set;}
}
Suppose the controller used is Home controller with Home actionResult
To use this modal to call it like this.
Public ActionResult Home(HomepageModel objmodel)
{
objmodel.registermodel.Fullname.......
//or
objmodel.loginmodel.Username
}
And for the view the same but referenced at the top
@model yourprojectname.models.HomepageModel
Cheers hope this helps someone out there!!!
mvc asp.net