0

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.

Vini
  • 1,978
  • 8
  • 40
  • 82

2 Answers2

1

I solved it by deactivating browserlink in VS 2015:

enter image description here

Then theses errors went away. I also use german windows.. so maybe there's a connection.

hko
  • 923
  • 9
  • 17
0

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

}
Paweł Staniec
  • 3,151
  • 3
  • 29
  • 41
  • I have had it all the way you have mentioned and still it did not work which forced me to change my code the way it is now. As i have mentioned in my question i had more errors and i should say by luck or whatever i got it fixed. stil remaining with on error. – Vini Oct 02 '15 at 10:45
  • can you update your question to include the errors you're getting? – Paweł Staniec Oct 02 '15 at 11:50
  • I am getting the error in the browser console. And it is in German. I think nobody would prefer me posting the error in German – Vini Oct 02 '15 at 12:06
  • And the error simply mentions element not found. It doesnt specify anything more – Vini Oct 02 '15 at 12:12
  • There is no way that anyone will be able help you if you don't say what exactly doesn't work. Which scripts do not work and are missing. Start by commenting out all your scripts in your views and leave only bundle references in your layout. jquery and jqueryval bundles should be all you need for your scenario – Paweł Staniec Oct 02 '15 at 12:14
  • When I click the create button nothing happens. – Vini Oct 02 '15 at 12:16
  • That is the problem I am facing. So in the Browser console I found this error statement. – Vini Oct 02 '15 at 12:17
  • I have commented the Scripts in my view. Still no change. Updated the question with the error in my Browser console. – Vini Oct 02 '15 at 12:21
  • Initially i had only both of them when i started getting a lot of errors, – Vini Oct 02 '15 at 12:22
  • Look at the HTTP traffic. Figure out if the problem is because of a broken request or a broken response. – Paweł Staniec Oct 02 '15 at 12:25
  • I am not sure if you are looking for something that I found. I get 401 unauthorized on the Get method for create in the first two lines then it is green with 200 Authorized. – Vini Oct 02 '15 at 12:30
  • I suppose there are no broken requests – Vini Oct 02 '15 at 12:33
  • Then it looks like you have also problem with your server-side. – Paweł Staniec Oct 02 '15 at 12:33
  • I am using local db. I have other tables in the program which are being executed fine. – Vini Oct 02 '15 at 12:35
  • This is something completely different and is not related to the original question you had. I have shown you example of how script bundles should be included, and how to use sections. If you have other problems start new question – Paweł Staniec Oct 02 '15 at 12:37
  • Sorry! I really do not understand when you tell i should be starting a new question? – Vini Oct 02 '15 at 12:39
  • But my question was after having all the script bundles i am getting the error. – Vini Oct 02 '15 at 12:40
  • And moreover even if i start a new question i would be having the same content as with this question. The only point changing would be i have the scripts removed. besides, everything would remain the same – Vini Oct 02 '15 at 12:41
  • Comments section is not a chat, sorry. Your problem is unclear and surely is not related to script bundles if you have set up your layout and views as per the example and msdn documentation. – Paweł Staniec Oct 02 '15 at 12:43
  • yes i have done all that the way you have mentioned. Thanks anyway. – Vini Oct 02 '15 at 12:45