I am working on razor project where I need to display jquery modal popup. The popup shows up fine when it’s not started from the accordion, but once I put it there, the button doesn’t show the popup, but instead triggers the function from different button.
I have this in the markup:
@using (Html.BeginForm("ASPXView", "Report", FormMethod.Post)) {
@Html.ValidationSummary(true,
"Password change was unsuccessful. Please correct the errors and try again.")
<div>
@Html.Hidden("Id", Model.Report.Id)
<div id="accordion">
@foreach (var item in Model.Parameters)
{
<h3><a href="#">@Html.LabelFor(m => item.Name, item.Prompt)</a></h3>
<div>
<div class="editor-label">
Search @*Html.TextBox("Search")*@
<input id="@("Search" + item.Name)" type="text" name="q" data-autocomplete="@Url.Action("QuickSearch/" + item.Name, "Report")" />
</div>
<div class="editor-field">
<select multiple id="@("Select" +item.Name)" name="@("Select" +item.Name)"></select>
</div>
<div class="removed">
<button id="opener">Open Dialog</button>
</div>
</div>
}
</div>
<p style="text-align: right">
<input type="submit" value="Submit" />
</p>
</div>
}
<div id="dialog" title="Basic dialog">
<p>Test Content.</p>
</div>
JS code:
<script type="text/javascript">
var openDialog = function () {
$('#dialog').dialog('option', 'buttons', {
"Cancel": function () {
$('#dialog').dialog('close');
}
});
$('#dialog').dialog('open');
};
$(function () {
$("#dialog").dialog({
autoOpen: false,
show: "blind",
hide: "explode"
});
$('#opener').click(openDialog);
})
</script>
As I said, when I’ll place Open Dialog below the dialog div, outside of accordion div, the popup comes up normal, but once I put the button there, popup doesn’t come out.
Thanks in advance for every advice
JS CODE UPDATE:
<script type="text/javascript">
$(function () {
$('#opener').click(function () {
$("#dialog").dialog('destroy');
$("#dialog").attr("title", "Your Title Heren");
$("#dialog").dialog({
height: 620,
width: 700,
modal: true
});
});
})
</script>
After replacing the code I had with this code, I can see the popup only from the 1st item in the accordion, but not from the other two.
Also, once the popup shows up on the screen, postback is happening, and event which is attached to another button, the submit button happens. Why do you think is that?
Thanks
may be you should have your jQuery Like this
Edited:
Mark up should go like this
jQuery Selector will be Like this