I am getting a Null exception when use ModelState.AddModelError
<p>I am using  ModelState.AddModelError in MVC to show error messages in view. I have this code:</p>

<pre><code>    [HttpPost]
    [Route("resetpassword")]
    public ActionResult ResetPassword(ResetPasswordView resetPasswordView)
    {

        if(resetPasswordView.Password == resetPasswordView.ConfirmPassword)
        {             
          .....
        }
        else
        {
            ModelState.AddModelError("", "Should be same password");
            return View("ResetPassword");
        }

        return View("ThankYouResetPassword");
    }
</code></pre>

<p>and this is the view that shows 3 textboxe that user enter email and password and when click on submit the method above will execute, I need to show a message when 2 textboxed are not same. </p>

<pre><code>@model Models.ResetPasswordView
&lt;div class="page resetPassword"&gt;
@using (Html.BeginForm("resetpassword", "Home", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    &lt;h5&gt;Reset Your Loan Center Password&lt;/h5&gt;
    &lt;table&gt;
        &lt;tr&gt;&lt;td&gt;Email Address&lt;/td&gt;&lt;td&gt;&lt;input type="email" name="Email" placeholder="jdoe@example.com" readonly value="@Model.Email" size="25"&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Password&lt;/td&gt;&lt;td&gt;&lt;input type="Password" name="Password" placeholder="Create Password" size="25"&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Confirm Password&lt;/td&gt;&lt;td&gt;&lt;input type="Password" name="ConfirmPassword" placeholder="Re-enter Password" size="25"&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td colspan="2"&gt;&lt;input type="submit" value="Reset Password"&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;
            &lt;td class="errMessage" colspan="2"&gt;
                @Html.ValidationSummary(true)
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
}
</code></pre>

<p></p>

<p>So when code goes to else part that needs to show the error message and goes to view I am getting the null exception in this line:</p>

<pre><code> @using (Html.BeginForm("resetpassword", "Home", FormMethod.Post))
</code></pre>

<p>This is error I am getting:</p>

<pre><code> System.NullReferenceException: Object reference not set to an instance of an object.
</code></pre>