Hello Ahmed,
Based on your understanding, you have done a good job. I appreciate, but I would like to suggest you something here.:)
First is never use Context in a controller Action Method.
Try using Services where the Context method would be written i.e. the Database operations should be done.
Have a Interface and a Service that would implement the members in the Interface.
Then you can inject dependency i.e. use the Interfaces in the controllers to access the DB/Query operations. For this you need to understand the Dependency Injection.
Getting Started with Dependency Injection[
^]
The above link would give you some idea.
Then the Controller would look like below:
public partial class AccountController :Controller
{
private IDemoVariable _demoVariable;
public AccountController(IDemoVariable demoVariable)
{
_demoVariable = demoVariable;
}
[HttpGet]
[AllowAnonymouse]
public ActionResult Register()
{
ViewBage.Countries=_demoVariable.MethodReturningTheQueryContextResults;
}
[HttpPost]
public ActionResult Register(RegistirationModel model)
{
if (ModelState.IsValid)
{
return RedirectToAction();
}
return view(model);
}
}
The service would define or implement the Context .
Hope you get some idea on this.
Thanks
:)