Filipe Costa Filipe Costa - 2 years ago 93
jQuery Question

.load start new path

in my project im trying to add a modal bootstrap to 1 of my views and i use

to load that view, the thing is when i try to load the view it only appears black, i tried to use
to watch the errors and i saw this


when i click the div to trigger the modal, i am in
, and I want to go to
and not all the url, I don't want to add the
url to the previous url that i had. How can i do that?

Here is my jquery function

$("#VisualizarSolucao").click(function (event) {
var id = $(this).attr("data-id");
$("#modal").load("../Solucoes/Details?id=" + id, function () {

i am loading the js in a external file, here is the VisualizarSolucao id that is called on the click event

<div class="col-md-10" style="border-left:2px solid black">
<p style="text-align:left;padding-top:5px">
<a href="" id="VisualizarSolucao" data-id="@i.SolucaoId" style="font-weight:900">@i.SolucaoTitulo</a>
<br />
<div class="col-md-offset-4 col-md-8" style="text-align:right">
<text>Criado por <a href="#">@i.User.UserName</a> no dia @i.DataCriacao</text>

Answer Source

The url in the .load() function would need to be "/Solucoes/Details?id=" + id, however you should always use the @Url.Action() method to ensure your url's as correctly generated.

Since the script is in an external file, and razor code is not parsed in external files, change you html to

<a href="#" class="VisualizarSolucao" data-url="@Url.Action("Details", "Solucoes", new { id = i.SolucaoId })">

Note that the id is changed to a class name (your generating duplicate id attributes in a loop which is invalid html). You should also remove the inline styles and use css instead.

Then change the script to (no need for event.preventDefault())

$('.VisualizarSolucao').click(function() { // class name selector
    var url = $(this).data('url'); // use data(), not attr()
    $("#modal").load(url, function () {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download