Remote validation shows error message but still lets the form submit and saves in database MVC 5
<p>The situation is, combination of <strong>Student Reg. No.</strong> and <strong>Select Course</strong> is always unique.</p>

<p>Upon selection of a combination which was saved before in database, the expected results are,</p>

<p><strong>First Expected Result:</strong></p>

<p>Error message “Selected Student has taken this course already” will appear.</p>

<p><strong>Second Expected Result:</strong></p>

<p>It will refrain the form from submitting until a different combination is selected which was not saved in database before.</p>

<p><strong>Current Result:</strong></p>

<p>First Expected Result is working well:</p>

<p><a href="https://i.stack.imgur.com/gHGTV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gHGTV.jpg" alt="enter image description here"></a></p>

<p>But, the Second Expected Result is not working. That is, it submits the form and saves the combination which was already saved in database before.</p>

<p>Can you please give a solution as I can get the Second Expected Result?</p>

<p>Thanks in advance.</p>

<p>For readability I have excluded all codes, html and scripts associated with Name, Email and Department.</p>

<p>Here is my Model,</p>

<pre><code>using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Web.Mvc;

namespace UniversityApplication.Models
{
public class CourseStudent
{
    [Required]
    [DisplayName("Student Reg. No.")]
    public string CourseStudentRegNo { get; set; }

    [Required]
    [Remote("IsCourseNameExists", "CourseStudents", AdditionalFields = "CourseStudentRegNo", ErrorMessage = "Selected Student has taken this course already.")]
    [DisplayName("Select Course")]
    public string CourseStudentCourse { get; set; }

    [Required]
    [DisplayName("Date")]
    [DataType(DataType.Date)]
    public DateTime CourseStudentRegDate { get; set; }
}
}
</code></pre>

<p>Here is my Controller,</p>

<pre><code>using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using UniversityApplication.Context;
using UniversityApplication.Models;

namespace UniversityApplication.Controllers
{
public class CourseStudentsController : Controller
{
    private ApplicationContext db = new ApplicationContext();

    public ActionResult StudentToCourse()
    {
        GenerateDropDownValue();
        return View();
    }


    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult StudentToCourse([Bind(Include = "CourseStudentID,CourseStudentRegNo,CourseStudentName,CourseStudentEmail,CourseStudentDepartmentCode,CourseStudentCourse,CourseStudentRegDate")] CourseStudent courseStudent)
    {
        GenerateDropDownValue();

        if (ModelState.IsValid)
        {
            db.CoursesStudents.Add(courseStudent);
            db.SaveChanges();
            ModelState.Clear();

            return View();
        }
        ModelState.Clear();

        return View();            
    }

private void GenerateDropDownValue()
    {
        List&lt;Student&gt; allRegisteredStudents = new List&lt;Student&gt;();
        List&lt;SelectListItem&gt; students = new List&lt;SelectListItem&gt;();

        List&lt;Course&gt; allCourses = new List&lt;Course&gt;();


        string studentName = "";
        string studentEmail = "";
        string studentDepartment = "";

        using (ApplicationContext db = new ApplicationContext())
        {
            allRegisteredStudents = db.Students.OrderBy(a =&gt; a.StudentRegNo).ToList();
        }

        foreach (var student in allRegisteredStudents)
        {
            students.Add(

                new SelectListItem()
                {
                    Value = student.StudentRegNo,
                    Text = student.StudentRegNo
                }
                );
        }

        ViewBag.Students = students;
        ViewBag.CourseCode = new SelectList(allCourses, "CourseCode", "CourseName");
        ViewBag.StudentName = studentName;
        ViewBag.StudentEmail = studentEmail;
        ViewBag.StudentDepartment = studentDepartment;
    }

    public JsonResult IsCourseNameExists(string CourseStudentCourse, string CourseStudentRegNo)
    {
        return Json(!db.CoursesStudents.Any(x =&gt; x.CourseStudentCourse == CourseStudentCourse &amp;&amp; x.CourseStudentRegNo == CourseStudentRegNo), JsonRequestBehavior.AllowGet);
    }    

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            db.Dispose();
        }
        base.Dispose(disposing);
    }
}
</code></pre>

<p>}</p>

<p>Here is my View,</p>

<pre><code>@model UniversityApplication.Models.CourseStudent

@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}

&lt;h2&gt;Create&lt;/h2&gt;


@using (Html.BeginForm()) 
{
@Html.AntiForgeryToken()

&lt;div class="form-horizontal"&gt;
    &lt;h4&gt;CourseStudent&lt;/h4&gt;
    &lt;hr /&gt;
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    &lt;div class="form-group"&gt;
        @Html.LabelFor(model =&gt; model.CourseStudentRegNo, htmlAttributes: new { @class = "control-label col-md-2" })
        &lt;div class="col-md-10"&gt;
            @Html.DropDownListFor(model =&gt; model.CourseStudentRegNo, @ViewBag.Students as SelectList, "Select Student", new { @class = "form-control" })
            @Html.ValidationMessageFor(model =&gt; model.CourseStudentRegNo, "", new { @class = "text-danger" })
        &lt;/div&gt;
    &lt;/div&gt;        

    &lt;div class="form-group"&gt;
        @Html.LabelFor(model =&gt; model.CourseStudentCourse, htmlAttributes: new { @class = "control-label col-md-2" })
        &lt;div class="col-md-10"&gt;
            @Html.DropDownListFor(model =&gt; model.CourseStudentCourse, @ViewBag.CourseCode as SelectList, "Select Course", new { @class = "form-control" })
            @Html.ValidationMessageFor(model =&gt; model.CourseStudentCourse, "", new { @class = "text-danger" })
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
        @Html.LabelFor(model =&gt; model.CourseStudentRegDate, htmlAttributes: new { @class = "control-label col-md-2" })
        &lt;div class="col-md-10"&gt;
            @Html.TextBoxFor(m =&gt; m.CourseStudentRegDate, new { @class = "date form-control", @readonly = "true" })
            @Html.ValidationMessageFor(model =&gt; model.CourseStudentRegDate, "", new { @class = "text-danger" })
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
        &lt;div class="col-md-offset-2 col-md-10"&gt;
            &lt;input type="submit" value="Enroll" class="btn btn-default" /&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
}

&lt;div&gt;
@Html.ActionLink("Back to List", "Index")
&lt;/div&gt;
&lt;link href="~/Content/themes/base/all.css" rel="stylesheet" /&gt;
@section Scripts {

&lt;script src="~/Scripts/jquery.validate.date.js"&gt;&lt;/script&gt;
@Scripts.Render("~/bundles/jqueryui")
@Styles.Render("~/Content/cssjqryUi")
@Scripts.Render("~/bundles/jqueryval")

&lt;script&gt;

$(document).ready(function () {
    $('.date').datepicker({ dateFormat: "dd/mm/yy" });
});
&lt;/script&gt;

}
</code></pre>