I have a simple mvc application in which I have login form in this login form I have student email and password which are coming from the text boxes this view is strongly type and binding with login model ,now i wanted to add one more field to be passed to controller from view and this new field is in anothet table like student house number ,i have added the property as public studentadrrss addrss,as here studentadrrss is a entity it comes in controller but emplty i want to get the student adress of that specific student and pass in controller or to get it in controller and pass in view how to do that
Loading
Chetan SanghaniPosted Jul 13, 2024, 6:13 AM
To achieve this, you need to pass both the login information and the student address from the view to the controller. Here’s how you can implement this in your ASP.NET MVC application:
Step-by-Step Implementation
Update the Login ViewModel:
First, add the
StudentAddressproperty to yourLoginViewModel.Assuming
StudentAddressis another model representing the student address details.Update the Login View:
Update your view to include the new address fields. Ensure the view is strongly typed to
LoginViewModel.Update the Controller:
In your controller, receive the
LoginViewModeland process the information.Explanation
LoginViewModel:
StudentAddressproperty to hold the student's address information.Login View:
LoginViewModel.AccountController:
Loginaction to receive theLoginViewModel.GetStudentAddressto fetch the student's address based on the email if it's not passed from the view.Loginmethod to authenticate the student and handle the address information.By following these steps, you will be able to pass the student address information from the view to the controller or fetch it in the controller and pass it to the view as needed.