Reputation: 23
I want to click on an item in the main page, pass in an ID, then load data in a modal based on that ID
I have the following code in the cshtml page where the click happens
<div class="modal" id="myModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
$.ajax({
type: "Post",
url: "/Home/GetImageFromLogId?LogId=" + this.specialId,
success: function (data) {
$("#modal-content").html(data);
$("#myModal").modal("show");
},
error: function () {
alert('error!');
}
})
I then have this in the homecontroller
[HttpPost] public ActionResult GetImageFromLogId(long LogId) { var requestedImageData = processIt.LoadGraphImageData(LogId); return PartialView(requestedImageData); }
processIt.LoadGraphImageData simply return an object with a date, image location, and some Id's
I would like to show this information in the modal, but I'm obviously missing something
I'm relatively new to MVC so struggling to figure out the missing parts
Upvotes: 0
Views: 1167
Reputation: 23
I needed to add the cshtml file and then add this
return PartialView("~/Views/Home/CameraImage.cshtml");
Upvotes: 1