Hi everyone I have a LogOn view look like this
<%= Html.TextBox("username", "", new { @style = "width:149px;border:1px solid #CCC" })%>
<%= Html.Password("password","",new { @style = "width:149px;border:1px solid #CCC" }) %>
<%= Html.DropDownList("SrvId", (SelectList)ViewData["ServerID"], new { @style = "width:149px;border:1px solid #CCC; font-family:'Trebuchet MS';" })%>
Basicly the above view is the template from ASP.NET MVC, I just add the Html.DropDownList that i'll use to choose the connection string
Below is the Account Controller
public ActionResult LogOn()
{
var list = new[] {
new ServerID { Id = 0, Name = "<Please Select>" },
new ServerID { Id = 1, Name = "Server1" },
new ServerID { Id = 2, Name = "Server2" },
};
var selectList = new SelectList(list, "Id", "Name", 0);
ViewData["ServerID"] = selectList;
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
Justification = "Needs to take same parameter type as Controller.Redirect()")]
public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)
{
if (!ValidateLogOn(userName, password))
{
return View();
}
FormsAuth.SignIn(userName, rememberMe);
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Customer");
}
}
This is the model which use to choose the Connection string that i got from internet
public partial class dbServiceModelDataContext : System.Data.Linq.DataContext
{
// Connection String Keys - stored in web.config
static string PrimaryConnectionStringKey = "SRVConnectionString";
static string SecondaryConnectionStringKey = "SRVConnectionString2";
protected static string ConnectionS
{
get
{
if (##how to pass the dropdownlist value here ??##)
{
return global::System.Configuration.ConfigurationManager.ConnectionStrings[PrimaryConnectionStringKey].ConnectionString;
}
else
{
return global::System.Configuration.ConfigurationManager.ConnectionStrings[SecondaryConnectionStringKey].ConnectionString;
}
}
}
public dbServiceModelDataContext() :
base(ConnectionS, mappingSource)
{
OnCreated();
}
}
my Question is how to pass value of DropDownList to the model ? I put my Connection String in Web.config Thanks..