isPost activates instantly upon loading webpage

2019-09-07 03:05发布

I have 2 forms on my cshtml web page. One

@if (WebSecurity.IsAuthenticated) {
                            <text>
                                Hello, <a class="email" href="~/Account/Manage" title="Manage">@WebSecurity.CurrentUserName</a>!
                                <form id="logoutForm" action="~/Account/Logout" method="post">
                                    @AntiForgery.GetHtml()
                                    <a href="javascript:document.getElementById('logoutForm').submit()">Log out</a>
                                </form>
                            </text>
                        } else {
                            <ul>
                                <!--li><a href="~/Account/Register">Register</a></li-->
                                <li><a href="~/Account/Login">Log in</a></li>
                            </ul>
                        }

second form

  <form action ="" id="query" method="post">  <!--need to search database for a match of medirecord, form is used here-->
      <div data-role="fieldcontain">
                <label for="name">Patient NRIC:&nbsp</label>
                <input type="text" name="nric" id="nric" value=""  />
                </div>  
    <input value="Search" type="submit" data-role="button" data-theme="b"  /><!--if cannot find display error msg else go to patient_hist.cshtml-->
             </form>

IsPost event

if(IsPost)
    {            
        String Nric = Request.Form["nric"];
         //var db = Database.Open("StarterSite");
         //var user = db.QuerySingle("SELECT * FROM Patient WHERE NRIC = @0", Nric);
         var user = "test";
         user = null;
         if(user != null)
         {
            <script type="text/javascript">
                alert("Not a user!");
            </script>
         }
         else
         {
                   <script type="text/javascript">
       alert("Its a user!");
      </script>
         }


    }

    else
    {
           <script type="text/javascript">
       alert("Not a Post");
      </script>
    }    

If i were to take out the else, upon clicking the button in the second form, the form will just refresh with nothing happening

标签: forms post razor
0条回答
登录 后发表回答