admin管理员组文章数量:1357707
I want to display partial view inside modal popup. I have one main page where I am calling partial view based on Id on button Click.
My Main View:
<table id="tblSearch" class="table table-hover">
<tr>
<th>
@Html.DisplayNameFor(m =>m.Name)
</th>
<th>
@Html.DisplayNameFor(m => m.Description)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)</span>
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
<input class="search btn-default" type="button" value="Search"
data-assigned-id="@item.Id" data-toggle="modal" data-target="#exampleModalLong" />
</td>
</tr>
}
</table>
My JavaScript to load Partial View:
$('.search').click(function () {
var id = $(this).data('assigned-id');
var route = '@Url.Action("DisplaySearchResults", "Home")?id=' + id;
$('#partial').load(route);
My Modal is:
<!-- Modal -->
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="partial"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Can anyone please guide me how to write JavaScript code to do this? Any help is highly appreciated.
I want to display partial view inside modal popup. I have one main page where I am calling partial view based on Id on button Click.
My Main View:
<table id="tblSearch" class="table table-hover">
<tr>
<th>
@Html.DisplayNameFor(m =>m.Name)
</th>
<th>
@Html.DisplayNameFor(m => m.Description)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)</span>
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
<input class="search btn-default" type="button" value="Search"
data-assigned-id="@item.Id" data-toggle="modal" data-target="#exampleModalLong" />
</td>
</tr>
}
</table>
My JavaScript to load Partial View:
$('.search').click(function () {
var id = $(this).data('assigned-id');
var route = '@Url.Action("DisplaySearchResults", "Home")?id=' + id;
$('#partial').load(route);
My Modal is:
<!-- Modal -->
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="partial"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Can anyone please guide me how to write JavaScript code to do this? Any help is highly appreciated.
Share Improve this question edited Dec 15, 2017 at 12:28 Brian Mains 50.7k35 gold badges155 silver badges260 bronze badges asked Dec 15, 2017 at 1:17 RajRaj 5551 gold badge13 silver badges32 bronze badges 5-
Have you read definition of
$.load()
method? What you may need isHtml.Partial
orHtml.RenderPartial
in hidden modal popup and show it whensearch
click event fired. – Tetsuya Yamamoto Commented Dec 15, 2017 at 1:33 - @TetsuyaYamamoto, I have more than one partial view and based on Id from button click, it displays the partial view. – Raj Commented Dec 15, 2017 at 1:44
- 2 So what problem are you having? – user3559349 Commented Dec 15, 2017 at 2:57
-
And show us your
DisplaySearchResults
method inHome
controller – TriV Commented Dec 15, 2017 at 3:07 - Please include your action (DisplaySearchResults) in the post. – Arjun Prakash Commented Dec 15, 2017 at 4:27
1 Answer
Reset to default 4The below code is working
<script type="text/javascript">
$(function () {
$('.search').click(function () {
var id = $(this).data('assigned-id');
var route = '@Url.Action("ViewTest", "Home")?id=' + id;
$('#partial').load(route);
});
});
</script>
<table id="tblSearch" class="table table-hover">
<tr>
<td>
<input class="search btn-default" type="button" value="Search"
data-assigned-id="1" data-toggle="modal" data-target="#exampleModalLong" />
</td>
</tr>
@* modify as per your code change, data-assigned-id="1" also *@
</table>
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="partial"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
Controller
public ActionResult Test()
{
//main view
return View();
}
public ActionResult ViewTest(int id)
{
//Write your logic here
return PartialView("_TestPartial");
}
Partial View
<div>
Sample Partial Views
</div>
本文标签: javascriptPartial View inside Bootstrap Modal popupStack Overflow
版权声明:本文标题:javascript - Partial View inside Bootstrap Modal popup - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744045942a2581523.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论