-2

I am doing an MVC5 Application..

I am rendering two partial views from controller method called from $(document).ready of the main view. But one method is never called.

Here is my view

<div class="dvPpal">
    <div class="dvMenuIzqEmpty">
        <div style="float:left;width:100%;height:20px;margin-bottom:20px">
        </div>
        <div style="float:left;width:100%;margin-left:25px; ">
            <img class="ImgNick" src="~/Content/Images/Iconos/PhotosSmall.png" />
        </div>

        <div style="float:left;width:100%;height:30px;" class="Sees">
        </div>
    </div>
    <div id="UserUpload">
    </div>
    <div class="dvRightPnl">
    </div>
</div> 

And here is my call

 <script language="javascript" type="text/javascript">
  $(document).ready(function () {
        FormCreateEdit();
        $("#dvRightPnl").load('@Url.Action("GetUploadsByUser", "Uploads")');
        $("#UserUpload").load('@Url.Action("GetUploadData", "Uploads", new { Upload_id = 0 })');
 });
 </script>

My controller method looks like this

 public async Task<PartialViewResult> GetUploadData(long Upload_id = 0)
        {
        return null;
        }

 public async Task<PartialViewResult> GetUploadsByUser()
        {
        return null;
        }

Only GetUploadData is called.

The method GetUploadsByUser is never called?

What I am missing?

Thanks

Diego
  • 2,238
  • 4
  • 31
  • 68
  • 1
    Are you sure it's never called, rather than just not producing any output? Have you tried adding a `console.log` to see how far it gets? Are any error messages displayed in the console? Are you sure that `#dvRightPnl` loads? – freginold Aug 23 '17 at 18:08
  • if one is being called, the other is being called. – Kevin B Aug 23 '17 at 18:08
  • Yes, is never called, but I just fixed it.. I am Answer it.. thanks – Diego Aug 23 '17 at 18:09
  • eh, no, .load is called regardless of whether or not elements existed in the collection, the difference is whether or not an ajax request is sent. – Kevin B Aug 23 '17 at 18:11
  • @KevinB Correct me if I'm wrong... `.load()` isn't only called once the element loads? – freginold Aug 23 '17 at 18:14
  • 1
    no, the element loading is irrelevant to the .load method in modern versions of jquery. – Kevin B Aug 23 '17 at 18:15
  • @KevinB Okay, thanks, gotta brush up on my reading.... – freginold Aug 23 '17 at 18:21

2 Answers2

0

It looks like you just need to fix a typo. Your script calls:

$("#dvRightPnl").load('@Url.Action("GetUploadsByUser", "Uploads")');

but your HTML assigns dvRightPnl as a class, not an ID:

<div class="dvRightPnl">

If you make them both the same (either change the jQuery selector to $(".dvRightPnl") or change the div in your HTML to <div id="dvRightPnl">) that should fix your problem.

freginold
  • 3,946
  • 3
  • 13
  • 28
-1

As soon as I saw the question, I realized my mistake...

Ht method that is never called i bind it to a div with class=dvRightPnl. I have to set id=dvRightPnl instead..

Insted of using

<div class="dvRightPnl"> </div>

I have to use

<div id="dvRightPnl">   </div>
Diego
  • 2,238
  • 4
  • 31
  • 68