C# MVC重定向无法正常工作
嗨,我在我的MVC项目中使用数据库优先的方法。我有一个操作,当用户单击Accept terms时,我调用存储过程 在这里,我一调用这个存储过程,它就在我的表中存储当前日期,并使TermsAcepted字段从false变为true。它工作得很好。我有这样的条件:只有当用户接受条款时,他们才可以重定向到默认页面。但即使在调用存储过程并更新日期之后,它也不会重定向到默认页面 我观察到的是,若我关闭并打开我的解决方案,那个么它将获取存储在数据库中的最新值,然后它将重定向到我需要的页面 那个么,在不重新启动VisualStudio的情况下,如何在数据库中的值更新后立即重定向到页面 我的行动:C# MVC重定向无法正常工作,c#,asp.net-mvc,database,razor,C#,Asp.net Mvc,Database,Razor,嗨,我在我的MVC项目中使用数据库优先的方法。我有一个操作,当用户单击Accept terms时,我调用存储过程 在这里,我一调用这个存储过程,它就在我的表中存储当前日期,并使TermsAcepted字段从false变为true。它工作得很好。我有这样的条件:只有当用户接受条款时,他们才可以重定向到默认页面。但即使在调用存储过程并更新日期之后,它也不会重定向到默认页面 我观察到的是,若我关闭并打开我的解决方案,那个么它将获取存储在数据库中的最新值,然后它将重定向到我需要的页面 那个么,在不重新启
public ActionResult Termspage()
{
TermsEntities updateterms = new TermsEntities();
var ID = Session["userID"];
if (ID != null)
{
updateterms.usp_UpdateUserTerms(Convert.ToInt32(ID), true);
updateterms.SaveChanges();
}
return View();
}
<body>
<div>
@using (Html.BeginForm("DefaultPage", "Home", FormMethod.Post, new { id = "frmIndex" }))
{
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<input type="submit" value="Accept Terms & Condition" />
</td>
</tr>
</table>
}
</div>
</body>
我的观点:
public ActionResult Termspage()
{
TermsEntities updateterms = new TermsEntities();
var ID = Session["userID"];
if (ID != null)
{
updateterms.usp_UpdateUserTerms(Convert.ToInt32(ID), true);
updateterms.SaveChanges();
}
return View();
}
<body>
<div>
@using (Html.BeginForm("DefaultPage", "Home", FormMethod.Post, new { id = "frmIndex" }))
{
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<input type="submit" value="Accept Terms & Condition" />
</td>
</tr>
</table>
}
</div>
</body>
@使用(Html.BeginForm(“DefaultPage”,“Home”,FormMethod.Post,new{id=“frmIndex”}))
{
}
在这里,即使在我的数据库中更新了详细信息,它也不会重定向到Defaultpage操作。但当我重新打开解决方案时,它将重定向到Defaultpage
更新:
public ActionResult Termspage()
{
TermsEntities updateterms = new TermsEntities();
var ID = Session["userID"];
if (ID != null)
{
updateterms.usp_UpdateUserTerms(Convert.ToInt32(ID), true);
updateterms.SaveChanges();
}
return View();
}
<body>
<div>
@using (Html.BeginForm("DefaultPage", "Home", FormMethod.Post, new { id = "frmIndex" }))
{
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<input type="submit" value="Accept Terms & Condition" />
</td>
</tr>
</table>
}
</div>
</body>
我尝试使用redirecttoAction,但当我使用它时,我发现此网页有重定向循环错误请使用
然后
代码中没有重定向。你只返回了一个
视图
@Dai我尝试了重定向到操作,但我得到的网页有重定向循环错误。哈,我忘了提及。我以前只尝试过这个,当我使用它时,我发现这个网页有一个重定向循环错误。@Ajay,请参阅我重定向到其他操作。为什么它会给你无限循环?嗨,我不能完全按照你说的那样使用。若我在If语句中使用redirecttoaction并试图运行,那个么并不是所有的代码路径都返回值。所以,即使在使用重定向之后,我也在if语句之后使用return View()。在详细信息中,您将id作为参数传递,我们需要在我的默认页面中传递它吗?我的默认页面中有redirecttoaction(“pagename”),所以我可以这样传递吗?重定向操作(“页面名”,id)?