2017-10-28 13 views
0

私は2つのかみそりの形をしています。私は両方の同じコントローラを使用します。ここで私はフォームを定義しています方法です:同じページに2つのかみそりの形があります。 2番目にエラーがあります

これは動作します:

@using (Html.BeginForm("Index", "Login", FormMethod.Post, new { enctype = "multipart/form-data" })) 

これは動作しません:

@using (Html.BeginForm("ResetPassword", "Login", FormMethod.Post, new { enctype = "multipart/form-data" })) 

はエラーを与える:

説明:未処理の例外が中に発生しました現在のWebリクエストの実行。エラーの詳細とコード内のどこで発生したのかについては、スタックトレースを参照してください。 return文を変更する必要が

[HttpPost] 
public ActionResult ResetPassword(LoginViewModel vm) 
{ 
    try 
    { 
     ViewBag.ErrorMsg = ""; 
     if (vm.confirmpass != vm.newPass) 
     { 
      ViewBag.ErrorMsg = "Passwords do not match."; 
     } else if (!String.IsNullOrWhiteSpace(vm.user) && !String.IsNullOrWhiteSpace(vm.newPass) && !String.IsNullOrWhiteSpace(vm.confirmpass)) 
     { 
      //this should be updated to be empty string once the database is setup 
      string sysproId = "1234"; 
      sysproId = ""; 

      //get from the database 
      string constr = ConfigurationManager.ConnectionStrings["mySQLConnStr"].ConnectionString; 
      using (MySqlConnection con = new MySqlConnection(constr)) 
      { 
       string query = "SELECT * from wp_portal_users where username='" 
        + vm.user + "' and ((tempPassword='" + vm.newPass + "' and NOW()<= tempPasswordValidity));"; 
       using (MySqlCommand cmd = new MySqlCommand(query)) 
       { 
        cmd.Connection = con; 
        con.Open(); 
        using (MySqlDataReader sdr = cmd.ExecuteReader()) 
        { 
         while (sdr.Read()) 
         { 
          sysproId = sdr["sysproID"].ToString(); 
         } 
        } 
       } 

       //if a user is found then update the password 
       if (!String.IsNullOrWhiteSpace(sysproId)) { 
        query = "Update wp_portal_users set password='" + vm.newPass + "' where username='" + vm.user + "'"; 
        using (MySqlCommand cmd2 = new MySqlCommand(query)) 
        { 
         cmd2.Connection = con; 
         con.Open(); 
         cmd2.ExecuteNonQuery(); 
        } 
       } 

       //close the db connection 
       con.Close(); 
      } 



      //log the user in if there was a match 
      if (!String.IsNullOrWhiteSpace(sysproId)) 
      { 
       //store the users details in the cookie 
       HttpCookie userInfo = new HttpCookie("123Cookie"); 
       userInfo["Userid"] = "my_portal";//this is the userID of the site and not the user 
       userInfo["CustomerId"] = sysproId; 

       //cookie expires everyday 
       userInfo.Expires.Add(new TimeSpan(0, 1, 0)); 
       Response.Cookies.Add(userInfo); 

       Session["sysproId"] = sysproId; 
       return RedirectToAction("Index", "Home"); 
      } 
      else 
      { 
       //user was not found. Show some error 
       vm.user = ""; 
       vm.pass = ""; 
       ViewBag.ErrorMsg = "Could not login. Please email us at [email protected] for help."; 
      } 
     } 

     return View(vm); 
    } 
    catch (Exception ex) 
    { 
     ViewBag.ErrorMsg = "Whoops! Please try again."; 
     return View(vm); 
    } 
} 
+0

コントローラメソッドを表示する(存在しないビューを返そうとしています) –

+1

ControllerActionはありますが、Views-FolderにresetPassword.cshtmlはありません。 – Nikolaus

答えて

1

:ここ

>Exception Details: System.InvalidOperationException: The view 'ResetPassword' or its master was not found or no view engine supports the searched locations. The following locations were searched: 
~/Views/Login/ResetPassword.aspx 
~/Views/Login/ResetPassword.ascx 
~/Views/Shared/ResetPassword.aspx 
~/Views/Shared/ResetPassword.ascx 
~/Views/Login/ResetPassword.cshtml 
~/Views/Login/ResetPassword.vbhtml 
~/Views/Shared/ResetPassword.cshtml 
~/Views/Shared/ResetPassword.vbhtml 

は、コントローラのメソッドです。同じ名前のビューは存在しないので、それは供給されるべきです。

リターン・ビュー( "Index"、vm);

私は..状況が、私は1つのかみそりのフォームを持っていたし、別の異なるアクションを打つだろうボタンを提出しているだろう..where

を持っていた過去に

0

私はすべての異なる送信ボタンにname属性を結合することによって、これを達成できます。例えば、

<button type="submit" name="submitBtn" value="Login" >Login</button> 
<button type="submit" name="submitBtn" value="Reset" >ResetPassword</button> 

今コントローラ側で...私はこのように... 1つのかみそりフォームが生活複数のかみそりのフォームとして作用することができるアクション

public ActionResult Index(LoginViewModel vm , string submitBtn) 
{ 
    if(submitBtn == "Login") 
    { 
    //do the login thing & 
     return View("Index", vm); 
    } 
    if(submitBtn == "Reset") 
    { 
    // do the reset password thing and 
    return View("Index", vm); 
    } 
} 

の種類ごとに例を記述します:)

0

this Error says that: "Hey Dud I search Views folder, but I can't find any kind of 'ResetPassword' there. "

コントローラの最後に表示すると表示されますが、(おそらく)表示は作成されません。

これを確認してください。

関連する問題