websss
asked on
create Dynamic data in partial view, and return html
I'm trying to load html data into a modal window
I've got it working, however I now need to pass in a ID to this to return the correct record
I currently have this code which is working
and then in the homecontroller
This is working fine and returns the data into the popup modal window
Its the next bit i'm stuck on
I need to pass in the ID and pull out the data relevant to that ID and display in the popup modal
I've already got the ID passed to the home controller, but i'm unsure how to display the html
in the home controller, this line gets a datetime, image location and some other strings of data
I would this like to return some formatted html i.e.
currently my cshtml for the partialview just has this text:
This is partial view
I'm unsure how to link the partialview html with the data from the object (imageLocation, imageDate etc)
Can someone help me solve that please
I've got it working, however I now need to pass in a ID to this to return the correct record
I currently have this code which is working
$.ajax({
type: "POST",
async: false,
url: "@Url.Action("CameraImage", "Home")",
data: "{'myId': '" + this.specialId + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$("#modal-body").html(data);
$("#myModal").modal("show");
},
error: function () {
alert('error!');
}
})
and then in the homecontroller
[HttpPost]
public PartialViewResult CameraImage(int myId)
{
//var requestedImageData = processData.LoadGraphImageData(myId);
return PartialView("~/Views/Home/CameraImage.cshtml");
}
This is working fine and returns the data into the popup modal window
Its the next bit i'm stuck on
I need to pass in the ID and pull out the data relevant to that ID and display in the popup modal
I've already got the ID passed to the home controller, but i'm unsure how to display the html
in the home controller, this line gets a datetime, image location and some other strings of data
var requestedImageData = processData.LoadGraphImageData(myId);
I would this like to return some formatted html i.e.
<div id="image">image pic goes here</div>
<div id="imageDate">12th jan 2016</div>
<div id="otherString">otherString goes here</div>
currently my cshtml for the partialview just has this text:
This is partial view
I'm unsure how to link the partialview html with the data from the object (imageLocation, imageDate etc)
Can someone help me solve that please
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
… then you'll be able to access the data in requestedImageData like you would with a normal Razor view.