I\'m trying to follow the post here, which may very well be wrong, to learn a little more about partial view loading in MVC. I know the basics of MVC but want to do more of
I got this exact same issue; loading the partial view as the whole page rather than in the defined div.
I was incorrectly presuming that my _Layout.cshtml
was including the jquery.unobtrusive-ajax.js
file as I didn't understand what the Bundles thingy(?) was doing. I thought it was being added by Bundles.
In my _Layout.cshtml
View it defines @RenderSection("scripts", required: false)
Which in English is; it's optional to include a section in your view called @scripts.
So no error is thrown if you don't include it (@section scripts) but the symptom is that the Ajax just renders in a new page if you don't.
To fix it: put the following in your view (I put it below the ...ViewBag.Title; }
)
@section scripts{
}
Sorry if my explanation is a bit rudimentary, I'm a bit new to this. Hoping this helps someone.