I am developing a MVC application with Remote validations. I am getting a No element found error in the browser console. I was getting so many Jquery not found errors that I could manage to remove by rendering the required Scripts. Now I have only one error in the browser console.
My View Script : Placed in the footer
@section Scripts {
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/scripts/jquery-1.10.2.js")
@Scripts.Render("~/Scripts/jquery.validate.min.js")
@Scripts.Render("~/Scripts/jquery.validate.js")
@Scripts.Render("~/Scripts/jquery.validate.unobtrusive.js")
@Scripts.Render("~/Scripts/jquery.validate.unobtrusive.min.js")
@Scripts.Render("~/Scripts/jquery-1.10.2.min.js")
@Scripts.Render("~/Scripts/jquery-ui-1.11.4.min.js")
@Scripts.Render("~/~/Scripts/jquery.unobtrusive-ajax.js")
}
In layout : Before the body (based on a suggestion I read)
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
<script src="@Url.Content("~/Scripts/jquery-ui-1.11.4.min.js")"></script>
How can I get this working? I have used remote validation and I suppose the Jquery used for the validation is missing in my code. But I have added all the Script files that was mentioned in the Remote validation tutorial I followed (I have added more though).
Remote Validation
[HttpPost]
public JsonResult DuplicateFamilyName(string FamilyName, int FamilyID)
{
if (FamilyID == 0)
{
bool exists = db.LsystemFamily.Any(x => x.FamilyName == FamilyName);
return Json(!exists, JsonRequestBehavior.AllowGet);
}
else
{
bool exists = db.LsystemFamily.Where(x => x.LsystemFamilyID != FamilyID).Any(x => x.FamilyName == FamilyName);
return Json(!exists, JsonRequestBehavior.AllowGet);
}
}
Edit
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryajax").Include(
"~/Scripts/jquery.unobtrusive*"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}