0

This link have a similar answer which works fine but some changes required above answer works fine, but my objective is a little bit different, I wanted to pass the variable from partial view who contains image URL, I want to use that URL in the main view somewhere. the scenario is, calling ajax to load the partial view and displaying in modal, partial view having a lot of ajax which calling controller for fetching folder and files from the server, on the response of ajax I got an image file URL in the partial view, now I want to pass that URL into the main view, how to do that?


the main view -> works fine enter code here

$(document).ready(function (){
          $("#button1").click(function ()    
           {
                    $("#modalbodypopup").load("/ControllerName/GetPartial");
                     jQuery.noConflict();
                     $('#imagePopup').modal('show');      
           });   
   });
</script>

controller -> works fine enter code here

       public IActionResult GetPartial()     
       {
            return PartialView("~/Views/Shared/_FileManager.cshtml");
       }

partial view calling different controller who returning HTML who have a lot of link and folders name and image file name now on the calling of ajax from the partial view, after a successful response, I got a file URL in the variable inside partial view javascript side which I want to pass to the main view because I am displaying that image there.

1 Answer 1

0

There are a couple of ways you can do this. Your GetPartial() method can do:

return PartialView("_FileManager");

And as long as the file is in the shared folder, MVC works out the path.

You can also return the contents of a file directly:

var file = File.ReadAllBytes(..);
return File(file, "image/png");

This allows you to stream the image url directly into the browser.

Sign up to request clarification or add additional context in comments.

1 Comment

<input type="hidden" id="partialDataId" value="/UserFiles/images/Screenshot1.png" /> overridig the value in the partial javascript side like $("#someDataFromPartialSomehow").val(fileURL); where fileURL=/UserFiles/images/Screenshot2.png , i need fileURL or hidden value in the main veiw in specific place it may be inside input value , hope you got that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.