C# 保存sql连接字符串时刷新管理页面
我已经在web.config文件中创建了更新sql连接字符串的功能。然而,由于某些原因,我无法让它在不刷新页面的情况下实时更新。刷新页面后,它会显示更改的值。单击“保存”时,它会保存在web.config文件中,但会返回到旧值 这是我的模型:C# 保存sql连接字符串时刷新管理页面,c#,html,sql,asp.net-mvc,C#,Html,Sql,Asp.net Mvc,我已经在web.config文件中创建了更新sql连接字符串的功能。然而,由于某些原因,我无法让它在不刷新页面的情况下实时更新。刷新页面后,它会显示更改的值。单击“保存”时,它会保存在web.config文件中,但会返回到旧值 这是我的模型: public void SAVEsqlConnection(string sqlConnection) { if (sqlConnection != System.Web.Configuration.WebConfigurat
public void SAVEsqlConnection(string sqlConnection)
{
if (sqlConnection != System.Web.Configuration.WebConfigurationManager.ConnectionStrings["sqlConnection1"].ToString())
{
Configuration sqlConnection1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var section = (ConnectionStringsSection)sqlConnection1.GetSection("connectionStrings");
section.ConnectionStrings["sqlConnection1"].ConnectionString = sqlConnection;
sqlConnection1.Save();
}
}
这是我的管理员控制器:
[HttpPost]
public ActionResult Admin(string txt_file_dest, string report_dest, string sql_Connection)
{
AdminModel Values = new AdminModel();
if (sql_Connection != null)
{
Values.SAVEsqlConnection(sql_Connection);
}
return View();
}
这是我的Admin.cshtml文件:
<input type="text" name="sql_Connection" value= "@System.Web.Configuration.WebConfigurationManager.ConnectionStrings["sqlConnection1"]">
:SQL Connection String<br>
<br>
<input type="submit" name="Save" value="Save Changes" />
:SQL连接字符串
任何帮助都将不胜感激。我有一个最后期限
提前感谢。查询完成后,您可以使用此JavaScript(1.2)刷新页面:
<script>
window.location.reload(true);
</script>
window.location.reload(true);
尽管如此,AJAX将是一个更好的解决方案,因为它将使页面自动加载新内容。等等,您认为这会如何工作?当然,您必须刷新页面,以便ASP.net在读取新连接字符串后重新生成内容。正确。但我需要在单击“保存”时对其进行刷新,以便用户不必刷新页面。这样就显示了他们更改为的字符串。
[HttpPost]
public ActionResult Admin(string txt_file_dest, string report_dest, string sql_Connection)
{
AdminModel Values = new AdminModel();
if (sql_Connection != null)
{
Values.SAVEsqlConnection(sql_Connection);
}
return RedirectToAction("actionname");//call same page action again
}