简体   繁体   English

MVC重定向无法正常工作

[英]MVC Redirect not working properly

Hi I AM using Database first approach in my MVC project. 嗨,我在我的MVC项目中使用数据库第一种方法。 I have an action where I am calling Stored procedure when user clicks on Accept terms. 我有一个操作,当用户点击Accept条款时,我调用存储过程。

Here as soon as i calling this stored procedure, in my table it is storing current date and making termsaccepted field from false to true. 在我调用此存储过程时,在我的表中,它存储当前日期并使termsaccepted字段从false变为true。 It is working fine. 它工作正常。 I have condition like only when user accepted terms they can redirect to Default page. 我有条件,只有当用户接受的条款,他们可以重定向到默认页面。 But even after calling stored procedure and updating date it is not redirecting to Default page. 但即使在调用存储过程和更新日期之后,它也不会重定向到默认页面。

And what I observed is, if i close and open my solution, then it is taking latest value stored in database and then it is redirecting to page which i need. 我观察到的是,如果我关闭并打开我的解决方案,那么它将采用存储在数据库中的最新值,然后重定向到我需要的页面。

So how can i redirect to page as soon as value updated in my database without restarting Visual Studio ? 那么,如果我的数据库中的值更新而不重新启动Visual Studio,我怎样才能重定向到页面?

My Action : 我的行动:

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();

        }

My 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>

Here it's not redirecting to Defaultpage action even after details are updated in my database. 即使在我的数据库中更新了详细信息,它也不会重定向到Defaultpage操作。 But when i reopen my solution then it is redirecting to Defaultpage. 但是当我重新打开我的解决方案时,它会重定向到Defaultpage。

Update : 更新:

I tried to use redirecttoAction but when I use this I am getting This webpage has redirect loop error 我试图使用redirecttoAction但是当我使用它时,我得到这个网页有重定向循环错误

Try PostRedirectGet method in MVC using RedirectToAction 使用RedirectToAction在MVC中尝试PostRedirectGet方法

public ActionResult Termspage()
{
  TermsEntities updateterms = new TermsEntities();
  var ID = Session["userID"];
   if (ID != null)
    {

        updateterms.usp_UpdateUserTerms(Convert.ToInt32(ID), true);

        updateterms.SaveChanges();

        return RedirectToAction("Detail", new {id=ID})

    }
  }

Then 然后

public ActionResult Detail(int id)
{    
 // get record
  return View();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM