I'm looking to see if there is anyway to pass a parameter to the controller itself and not a method inside the controller.
I use named connection strings with parameters for my ADO.NET models. This means I must pass a parameter every time I call the model
MyEntities myentity = new MyEntities(Param);
We do this because each division in our company has it's own mirrored SQL server and when using data we want the local divisions data.
The problem I face is that I cannot put the connection to the Model outside of a Method because it requires a parameter.
What I currently have to do is this
namespace WebApps.Controllers
{
public class MyController : Controller
{
public ActionResult Index(string Param)
{
MyEntities myentity = new MyEntities(Param);
var db = myentity.table;
return View(db);
}
}
}
What I'd like to do is this...
namespace WebApps.Controllers
{
public class MyController : Controller
{
MyEntities myentity = new MyEntities(Param);
public ActionResult Index()
{
var db = myentity.table;
return View(db);
}
}
}
This would also allow me to properly use a dispose method. I can't currently use it because I need to pass that parameter to close the db. (it doesn't exist outside the method)
This fails...
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.Dispose();
}
base.Dispose(disposing);
}
Could anyone tell me if passing a parameter directly to the controller is possible?
Param(but my read may be wrong).Paraminstantiated? One alternative is a controller factory...