Vini Vini - 5 months ago 21
Javascript Question

No element found Firefox Console :MVC

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)
{
//bool idExists = db.LsystemFamily.Any(id=>id.LsystemFamilyID.Equals(FamilyID));
if (FamilyID == 0)
{
bool exists = db.LsystemFamily.Any(x => x.FamilyName == FamilyName);
//var name = db.LsystemFamily.Where(x => x.FamilyName.Equals(FamilyName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
return Json(!exists, JsonRequestBehavior.AllowGet);
}
else
{
bool exists = db.LsystemFamily.Where(x => x.LsystemFamilyID != FamilyID).Any(x => x.FamilyName == FamilyName);
//var name = db.LsystemFamily.Where(x => x.FamilyName.Equals(FamilyName, StringComparison.CurrentCultureIgnoreCase) && x.LsystemFamilyID != FamilyID).FirstOrDefault();
return Json(!exists, JsonRequestBehavior.AllowGet);
}
}


EDIT

getPreventDefault() sollte nicht mehr verwendet werden. Verwenden Sie stattdessen defaultPrevented. jquery-1.10.2.js:5389:0
Kein Element gefunden send:1:1
Kein Element gefunden send:1:1
Kein Element gefunden send:1:1
Kein Element gefunden


Edit:

I have removed the Json validation from my program. Still it doesn't resolve the issue. Based on Torm's comments, i have done the http traffic analysis and have found there are no missing or broken requests and responses. Still I have the create button not working. Not posting any values.

Answer

Let us get things straight.

In your layout you reference scripts that are required for your application to work. In default MVC5 project template you have them bundled into packages for site performance reasons (http://www.asp.net/mvc/overview/performance/bundling-and-minification). Your Layout should look similar to the below (javascript should go to the bottom of the - that is the best practice):

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>

    <div class="container body-content">
        @RenderBody()
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

Please note that script bundles are defined by default in ~/App_Start/BundleConfig.cs file Note also the RenderSection line - this is definition of a place in your layout where your scripts from Views will show if you will add the following in your View

@section scripts {

// your javascript code here

}